Ihor Radchenko writes: > Hello, > > I am trying to figure out how to programmatically capture output of a > multi-line bash script in comint buffer. > > Consider: > > [yantar92:/tmp] $ >> if true >> then >> echo "hello" >> fi > hello > > Each line is submitted to shell via comint-send-input and, AFAIK, the > result can be collected using `comint-output-filter-functions'. > > I expect the `comint-output-filter-functions' to be called on "hello" > line. However, it does not seem to be the case. Empty "" corresponding > to "> " PS2 prompts upon sending incomplete script lines are also > passed. > > Is it possible to distinguish the actual script output, empty lines in > the actual script output, and the incomplete prompts? You could prepend your multiline command with a dummy 'echo multiline_starts_here' command have your 'comint-output-filter-functions' discard output that arrives before "multiline_starts_here". Or maybe inject something like 'oldps=$PS2; PS2=""' before the command and 'PS2=$oldps' after the command. But whether this works could depend on the shell, some shells might have something like $PS3 or $RPS1, for example. You could also accept-process-output after sending each individual line separately, but this depends on the user not customizing PS2="" in his bashrc. As far as Emacs is concerned, PS1/PS2 prompts and non-prompt process output is all data, read from a single file descriptor. I don't think it's possible to distinguish them reliably without the above tricks or some other heuristics.