You can get zsh to print a segmentation error message from a job if you run it as a background job and then immediately bring it to the forefront.
"$exepath" " $@ " & fg
This will cause zsh print messages for signals in the job running for $exepath .
The disadvantage is that you get a little more than you expected for:
% crun faulty.c faulty.c:1:5: warning: 'main' is usually a function [-Wmain] int main=0; ^~~~ [2] 2080 [2] - running "$exepath" " $@ " zsh: segmentation fault (core dumped) "$exepath" " $@ "
But as shown, you will get segfault messages printed in the terminal.
Since messages are printed by the interactive shell and not by the failure process, job messages are not redirected if you try to redirect stdout or stderr .
So, on the one hand, if you try to extract a useful result from your process and redirect it to another place, you do not need to worry about the fact that work messages are interfering. But it also means that you will not receive a segfault message if you try to redirect it with a stderr redirect.
Here's a demo of this effect, with line breaks, added between commands for clarity:
% crun good.c > test [2] 2071 [2] - running "$exepath" " $@ " % cat test Hello, world! % crun faulty.c 2>test [2] 2092 [2] - running "$exepath" " $@ " zsh: segmentation fault (core dumped) "$exepath" " $@ " % cat test faulty.c:1:5: warning: 'main' is usually a function [-Wmain] int main=0; ^~~~
For more information, see the zsh job and signal documentation . You can also pull out the C file where the magic happens .
source share