fix: don't write empty stdout and stderr
This commit is contained in:
parent
9aa142ffa6
commit
1689848851
6 changed files with 74 additions and 48 deletions
|
@ -321,12 +321,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
|
@ -334,12 +336,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &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?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
|
@ -274,12 +274,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
|
@ -287,12 +289,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
|
|
|
@ -264,12 +264,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
|
@ -277,12 +279,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
|
|
|
@ -275,12 +275,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
|
@ -288,12 +290,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
|
|
|
@ -255,12 +255,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
|
@ -268,12 +270,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
|
|
|
@ -273,12 +273,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
|
@ -286,12 +288,14 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
|
|
Loading…
Reference in a new issue