From 17e815348b0352a9b2d7082f195bc5a51c698591 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 25 Apr 2012 13:26:56 -0700 Subject: [PATCH] Fix to drain command output from quit commands before returning from job_continue This should fix the bug where output from commands and builtins gets incorrectly interleaved. I think this is a very long-standing bug that predates my work on the shell --- proc.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/proc.cpp b/proc.cpp index e6cc4ab2d..6d642eb66 100644 --- a/proc.cpp +++ b/proc.cpp @@ -1057,9 +1057,15 @@ void job_continue (job_t *j, int cont) got_signal = 0; quit = job_is_stopped( j ) || job_is_completed( j ); } - - while( got_signal && !quit ) - ; + while (got_signal && !quit); + + if (quit) { + // It's possible that the job will produce output and exit before we've even read from it. + // We'll eventually read the output, but it may be after we've executed subsequent calls + // This is why my prompt colors kept getting screwed up - the builtin echo calls + // were sometimes having their output combined with the set_color calls in the wrong order! + read_try(j); + } if( !quit ) {