Skip to content

Commit be8e5aa

Browse files
authored
fix(cli): duplicated newlines on child process output (#8042)
1 parent 94bef1c commit be8e5aa

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

.changes/fix-cmd-output.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@tauri-apps/cli": patch:bug
3+
"tauri-cli": patch:bug
4+
"tauri-bundler": patch:bug
5+
---
6+
7+
Fixes duplicated newlines on command outputs.

examples/api/src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/bundler/src/bundle/common.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use log::debug;
88
use std::{
99
ffi::OsStr,
1010
fs::{self, File},
11-
io::{self, BufReader, BufWriter},
11+
io::{self, BufRead, BufReader, BufWriter},
1212
path::Path,
1313
process::{Command, ExitStatus, Output, Stdio},
1414
sync::{Arc, Mutex},
@@ -165,33 +165,31 @@ impl CommandExt for Command {
165165
let stdout_lines = Arc::new(Mutex::new(Vec::new()));
166166
let stdout_lines_ = stdout_lines.clone();
167167
std::thread::spawn(move || {
168-
let mut buf = Vec::new();
168+
let mut line = String::new();
169169
let mut lines = stdout_lines_.lock().unwrap();
170170
loop {
171-
buf.clear();
172-
if let Ok(0) = tauri_utils::io::read_line(&mut stdout, &mut buf) {
171+
line.clear();
172+
if let Ok(0) = stdout.read_line(&mut line) {
173173
break;
174174
}
175-
debug!(action = "stdout"; "{}", String::from_utf8_lossy(&buf));
176-
lines.extend(buf.clone());
177-
lines.push(b'\n');
175+
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
176+
lines.extend(line.as_bytes().to_vec());
178177
}
179178
});
180179

181180
let mut stderr = child.stderr.take().map(BufReader::new).unwrap();
182181
let stderr_lines = Arc::new(Mutex::new(Vec::new()));
183182
let stderr_lines_ = stderr_lines.clone();
184183
std::thread::spawn(move || {
185-
let mut buf = Vec::new();
184+
let mut line = String::new();
186185
let mut lines = stderr_lines_.lock().unwrap();
187186
loop {
188-
buf.clear();
189-
if let Ok(0) = tauri_utils::io::read_line(&mut stderr, &mut buf) {
187+
line.clear();
188+
if let Ok(0) = stderr.read_line(&mut line) {
190189
break;
191190
}
192-
debug!(action = "stderr"; "{}", String::from_utf8_lossy(&buf));
193-
lines.extend(buf.clone());
194-
lines.push(b'\n');
191+
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
192+
lines.extend(line.as_bytes().to_vec());
195193
}
196194
});
197195

tooling/cli/src/interface/rust/desktop.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ fn build_dev_app<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
207207
break;
208208
}
209209
let _ = io_stderr.write_all(&buf);
210-
if !buf.ends_with(&[b'\r']) {
211-
let _ = io_stderr.write_all(b"\n");
212-
}
213210
lines.push(String::from_utf8_lossy(&buf).into_owned());
214211
}
215212
});

tooling/cli/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::io::{BufReader, Write};
2424
use std::process::{exit, Command, ExitStatus, Output, Stdio};
2525
use std::{
2626
ffi::OsString,
27+
io::BufRead,
2728
sync::{Arc, Mutex},
2829
};
2930

@@ -226,33 +227,31 @@ impl CommandExt for Command {
226227
let stdout_lines = Arc::new(Mutex::new(Vec::new()));
227228
let stdout_lines_ = stdout_lines.clone();
228229
std::thread::spawn(move || {
229-
let mut buf = Vec::new();
230+
let mut line = String::new();
230231
let mut lines = stdout_lines_.lock().unwrap();
231232
loop {
232-
buf.clear();
233-
if let Ok(0) = tauri_utils::io::read_line(&mut stdout, &mut buf) {
233+
line.clear();
234+
if let Ok(0) = stdout.read_line(&mut line) {
234235
break;
235236
}
236-
debug!(action = "stdout"; "{}", String::from_utf8_lossy(&buf));
237-
lines.extend(buf.clone());
238-
lines.push(b'\n');
237+
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
238+
lines.extend(line.as_bytes().to_vec());
239239
}
240240
});
241241

242242
let mut stderr = child.stderr.take().map(BufReader::new).unwrap();
243243
let stderr_lines = Arc::new(Mutex::new(Vec::new()));
244244
let stderr_lines_ = stderr_lines.clone();
245245
std::thread::spawn(move || {
246-
let mut buf = Vec::new();
246+
let mut line = String::new();
247247
let mut lines = stderr_lines_.lock().unwrap();
248248
loop {
249-
buf.clear();
250-
if let Ok(0) = tauri_utils::io::read_line(&mut stderr, &mut buf) {
249+
line.clear();
250+
if let Ok(0) = stderr.read_line(&mut line) {
251251
break;
252252
}
253-
debug!(action = "stderr"; "{}", String::from_utf8_lossy(&buf));
254-
lines.extend(buf.clone());
255-
lines.push(b'\n');
253+
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
254+
lines.extend(line.as_bytes().to_vec());
256255
}
257256
});
258257

0 commit comments

Comments
 (0)