fix: don't write empty stdout and stderr

This commit is contained in:
Nikita Podvirnyi 2024-07-19 14:12:08 +02:00
parent 9aa142ffa6
commit 1689848851
No known key found for this signature in database
GPG key ID: 859D416E5142AFF3
6 changed files with 74 additions and 48 deletions

View file

@ -321,10 +321,12 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -334,10 +336,12 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -347,6 +351,8 @@ pub fn run() -> anyhow::Result<()> {
}
}
game_output.flush()?;
// Workaround for fast process closing (is it still a thing?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));

View file

@ -274,10 +274,12 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -287,10 +289,12 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}

View file

@ -264,10 +264,12 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -277,10 +279,12 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}

View file

@ -275,10 +275,12 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -288,10 +290,12 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}

View file

@ -255,10 +255,12 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -268,10 +270,12 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}

View file

@ -273,10 +273,12 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b" [stdout] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}
@ -286,10 +288,12 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
if !buf.is_empty() {
for line in buf.split(|c| c == &b'\n') {
game_output.write_all(b"[!] [stderr] ")?;
game_output.write_all(line)?;
game_output.write_all(b"\n")?;
}
}
}