Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Redirecting a programs job control messages to parent's STDOUT



Meant to reply to this before; it got lost in the aftermath of
returning from a vacation.

On Mon, Jul 10, 2017 at 2:16 PM, zv <zv@xxxxxxxx> wrote:
> I've defined a function in my .zshrc to compile & run a file

What's going on here is that the function is considered to be running
within the current shell, so job status messages for the exit status
of the function are not printed.  The exit status of the function is
the status of the last command it executed, so if you were to examine
the value of $? (or $status) after the function was done, you would
see that it reflects the failure.  The lack of message has nothing to
do with how the executable or path to it was created.

So you have a couple of choices:
1.  Run the command in the background so full job control applies
during the function, which is effectively what Vartan describes; or
2.  Examine the exit status yourself and print  your own message.

E.g. if you end your crun function with

   $exepath "$@"
   integer stat=$status
   if (( stat > 128 )); then print -u2 -- ${exepath}: exited with
SIG${signals[stat-127]}; fi
   return stat

You'll see something like

   faulty.c: exited with SIGSEGV

You could also/instead "setopt print_exit_value" which would give something like

   zsh: exit 139



Messages sorted by: Reverse Date, Date, Thread, Author