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,12 +321,14 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
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")?;
}
}
}
// Redirect stdout to the game.log file
if let Some(stderr) = &mut child.stderr {
@ -334,12 +336,14 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
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")?;
}
}
}
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {
@ -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,12 +274,14 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
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")?;
}
}
}
// Redirect stdout to the game.log file
if let Some(stderr) = &mut child.stderr {
@ -287,12 +289,14 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
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")?;
}
}
}
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {

View file

@ -264,12 +264,14 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
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")?;
}
}
}
// Redirect stdout to the game.log file
if let Some(stderr) = &mut child.stderr {
@ -277,12 +279,14 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
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")?;
}
}
}
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {

View file

@ -275,12 +275,14 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
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")?;
}
}
}
// Redirect stdout to the game.log file
if let Some(stderr) = &mut child.stderr {
@ -288,12 +290,14 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
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")?;
}
}
}
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {

View file

@ -255,12 +255,14 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
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")?;
}
}
}
// Redirect stdout to the game.log file
if let Some(stderr) = &mut child.stderr {
@ -268,12 +270,14 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
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")?;
}
}
}
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {

View file

@ -273,12 +273,14 @@ pub fn run() -> anyhow::Result<()> {
stdout.read_to_end(&mut buf)?;
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")?;
}
}
}
// Redirect stdout to the game.log file
if let Some(stderr) = &mut child.stderr {
@ -286,12 +288,14 @@ pub fn run() -> anyhow::Result<()> {
stderr.read_to_end(&mut buf)?;
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")?;
}
}
}
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {