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

Redirecting a programs job control messages to parent's STDOUT



I've defined a function in my .zshrc to compile & run a file with the function
below:

  crun() {
      local file=$1
      shift
      local exepath="$(mktemp)"

      if [[ $file =~ "\.c$" ]]; then
          gcc -g -Wall $file -o $exepath || return $?
      else
          echo "no filetype detected"
          return 126
      fi

      $exepath "$@"
  }

Which is called like so:

  % crun source.cc arg_1 arg_2

This works for normal program, but has the problem that the shell's job control
messages, such as those generated from a segfault, do not appear.

As an example:

  % echo 'int main=0' >> /tmp/faulty.c # a crashing c program
  % crun faulty.c
  % # no output generated

Whereas the equivalent interactive commands would generate this:

  % g++ faulty.c -o /tmp/faulty && /tmp/faulty
  [1] 2894 segmentation fault (core dumped) # 🢀 zsh's job control output for
SIGSEGV

I've tried a number of different ways to trap the signal or have the invoking
("parent") shell to treat "constructed binaries" identically to an ordinary
executable/command but nothing seems to work without a hacks large enough to
morally bankrupt me.

Is there any way to display these messages for a crashing executable whose path
is dynamically calculated? Ideally without writing your own trap/signal handlers
+ exec, using `sh -c "$exepath $@"`, or writing a totally new program entirely)

- zv



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