Skip to content

Commit

Permalink
Fix PrintThread: Read stderr as bytes instead of str (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
NobodyXu authored Aug 2, 2023
1 parent 7adebb9 commit 3eb7c38
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3830,14 +3830,20 @@ impl PrintThread {
// location to another.
let print = thread::spawn(move || {
let mut stderr = BufReader::with_capacity(4096, pipe_reader);
let mut line = String::with_capacity(20);
let mut stdout = io::stdout();
let mut line = Vec::with_capacity(20);
let stdout = io::stdout();

// read_line returns 0 on Eof
while stderr.read_line(&mut line).unwrap() != 0 {
writeln!(&mut stdout, "cargo:warning={}", line).ok();
// read_until returns 0 on Eof
while stderr.read_until(b'\n', &mut line).unwrap() != 0 {
{
let mut stdout = stdout.lock();

stdout.write_all(b"cargo:warning=").unwrap();
stdout.write_all(&line).unwrap();
stdout.write_all(b"\n").unwrap();
}

// read_line does not clear the buffer
// read_until does not clear the buffer
line.clear();
}
});
Expand Down

0 comments on commit 3eb7c38

Please sign in to comment.