zsh-users
 help / color / mirror / code / Atom feed
From: zv <zv@nxvr.org>
To: zsh-users@zsh.org
Subject: Redirecting a programs job control messages to parent's STDOUT
Date: Mon, 10 Jul 2017 14:16:00 -0700	[thread overview]
Message-ID: <ok0qqb$v09$1@blaine.gmane.org> (raw)

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


             reply	other threads:[~2017-07-10 21:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10 21:16 zv [this message]
2017-07-25 19:33 ` zv
2017-07-25 21:03 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ok0qqb$v09$1@blaine.gmane.org' \
    --to=zv@nxvr.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).