From b9729227347e0532891321548b31579b80376bdd Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 Aug 2020 22:58:33 +0200 Subject: git-sugdiff: Fix output by waiting for child process I thought I'd resolved this problem by adding the `--no-pager` flag in 76079daf1e2175d02c9c584e47a21650fce30bb6, but it turns out that didn't fix it. When running the command, I'd get the following output, with the shell prompt preceding the start of the diff, and the command hanging without exiting to a new prompt line until a new interaction: $ ./target/debug/git-sugdiff 459692838 $ diff --git a/src/server.rs b/44ff3b520321467a9220965d13f997690ff3fda7 index d9eee95..44ff3b5 100644 --- a/src/server.rs +++ b/44ff3b520321467a9220965d13f997690ff3fda7 @@ -73,7 +73,7 @@ impl Server { internal_server_error(&mut raw_request.stdout()) }, Error::ConduitResponse { .. } => { error!("Error [-getting-]{+from+} response: {}", e); internal_server_error(&mut raw_request.stdout()) }, Turns out I need to wait for the command to exit in order to properly execute the external command. --- src/bin/git-sugdiff.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/git-sugdiff.rs b/src/bin/git-sugdiff.rs index 13c3292..ab893f0 100644 --- a/src/bin/git-sugdiff.rs +++ b/src/bin/git-sugdiff.rs @@ -58,7 +58,7 @@ fn main() { }, }; - match Command::new("git") + let mut child = match Command::new("git") .arg("--no-pager") .arg("diff") .args(&diff_args) @@ -66,6 +66,14 @@ fn main() { .arg(blob.to_string()) .spawn() { + Ok(c) => c, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::UNAVAILABLE); + }, + }; + + match child.wait() { Err(e) => { gseprintln!(e); process::exit(exitcode::UNAVAILABLE); -- cgit v1.2.3