http://qs321.pair.com?node_id=11120245


in reply to Effect of redirecting output to /dev/null on $? value

`$cmd` usually involves running /bin/sh with -c and the value of $cmd as arguments.

The use of the shell is optimized away if the command is simple enough. That is apparently the case in the first snippet.

In the second snippet, you are getting the exit status of /bin/sh. It returns 0x80 | signal_num when the program it runs is killed by a signal.

You could use the following to execute the program in the child process instead of creating a grandchild:

`exec my_executable_that_seg_faults >/dev/null`;

And you can avoid the shell entirely using IPC::Run.

Update: Added exec (before I noticed jcb mentioning it).