Project

General

Profile

Actions

Backport #5253

closed

PTY with wait incorrectly sets exit status for exit command

Added by thinkerbot (Simon Chiang) about 13 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
[ruby-core:39216]

Description

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.


Files

pty_exitstatus_test.rb (730 Bytes) pty_exitstatus_test.rb thinkerbot (Simon Chiang), 09/01/2011 05:34 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0