Issue #5253 has been updated by Simon Chiang.


Apologies for the delay in reply, for some reason I don't get email updates even though I'm watching this ticket.

That is a reasonable assertion that the behavior should be consistent PTY.spawn to Kernel.spawn.  I'm still curious, is the behavior correct?  Specifically, why doesn't/can't spawn return the exit status as specified by 'exit'?

I know in the case of system a 127 can be returned for a command that is not found... so maybe it's not looking up exit because it's a built-in utility... but I'm not clear why returning 1 is could be correct for spawn.  I am confused and would appreciate clarification if you have time to explain.


----------------------------------------
Backport #5253: PTY with wait incorrectly sets exit status for exit command
http://redmine.ruby-lang.org/issues/5253

Author: Simon Chiang
Status: Open
Priority: Low
Assignee: 
Category: 
Target version: 


Realizing this is irrelevant under normal usage, it appears wait on a PTY process does not set the correct exit status for an 'exit' command.  For example:

    PTY.spawn("exit 8") do |r,w,pid|
      Process.wait(pid)
    end
    $?.exitstatus  # => 1

Incidentally 'system' also appears to suffer from this unexpected behavior.

    system "exit 8"
    $?.exitstatus  # => 127

I think that either the most obvious exit status (8) should be set by both PTY and system or, if for some reason that can't happen then the behavior should be consistent between them.  A test case is attached.

Note that on 1.9.3-preview1 you get different behavior.  The PTY code results in "Errno::ENOENT: No such file or directory - exit 8".  
Also, a similar inconsistency happens with an empty string (although I don't know what the correct behavior is in this case):

    PTY.spawn("") do |r,w,pid|
      Process.wait(pid)
    end
    $?.exitstatus  # => 1
    
    system ""
    $?.exitstatus  # => 127

I know, I know... these are edge cases!  I won't try to argue calling PTY with an exit command or empty string is normal, but it came up in exploration while trying to make some example code. 



-- 
http://redmine.ruby-lang.org