rtomayko / posix-spawn

Ruby process spawning library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[macOS] POSIX::Spawn.system stale $? for missing commands

felixbuenemann opened this issue · comments

If the command run by POSIX::Spawn.system fails to execute because it was not found (Errno:ENOENT raised by POSIX::Spawn.spawn), the content of the $? global variable is not updated on macOS 10.12.14, which differs from the behavior of Kernel.system which sets $? to an Instance of Process::Status with exitstatus 127.

macOS 10.12.4:

$ ruby -v
ruby 2.2.7p470 (2017-03-28 revision 58194) [x86_64-darwin16]
$ irb
2.2.6 :001 > $?
 => nil
2.2.6 :002 > Kernel.system "foo"
 => nil
2.2.6 :003 > $?
 => #<Process::Status: pid 20175 exit 127>
2.2.6 :004 >
$ irb -r posix/spawn
2.2.6 :001 > $?
 => nil
2.2.6 :002 > POSIX::Spawn.system "foo"
 => false
2.2.6 :003 > $?
 => nil
2.2.6 :004 >

Linux (Debian Jessie):

Status: Downloaded newer image for ruby:2.2
root@0cd5cc5c4feb:/# gem install --no-document posix-spawn
Fetching: posix-spawn-0.3.13.gem (100%)
Building native extensions.  This could take a while...
Successfully installed posix-spawn-0.3.13
1 gem installed
root@0cd5cc5c4feb:/# ruby -v
ruby 2.2.7p470 (2017-03-28 revision 58194) [x86_64-linux]
root@0cd5cc5c4feb:/# irb
irb(main):001:0>
root@0cd5cc5c4feb:/# irb
irb(main):001:0> $?
=> nil
irb(main):002:0> Kernel.system "foo"
=> nil
irb(main):003:0> $?
=> #<Process::Status: pid 38 exit 127>
irb(main):004:0>
root@0cd5cc5c4feb:/# irb -r posix/spawn
irb(main):001:0> $?
=> nil
irb(main):002:0> POSIX::Spawn.system "foo"
=> false
irb(main):003:0> $?
=> #<Process::Status: pid 41 exit 127>
irb(main):004:0>

Note that $? stays nil in the POSIX::Spawn case on macOS.

This issue is loosely related to and was extracted from #81.

I have also tested this with ruby 2.4.1 on both Linux and macOS, but the results are the same as with ruby 2.2.7.