Issue #16791 has been updated by Dan0042 (Daniel DeLorme).


nobu (Nobuyoshi Nakada) wrote in #note-7:
> That executes `exit(nil)` and results in `TypeError`.

Ah, interesting, I was testing in irb where `exit(nil)` was equivalent to `exit(0)`

Eregon (Benoit Daloze) wrote in #note-8:
> nobu (Nobuyoshi Nakada) wrote in #note-7:
> > It may be acceptable to let `exit` accept a `SystemExit` instance though.
> 
> I think that would be useful.
> I'd guess it would behave as something like:
> ```ruby
> # useful if terminated by a signal:
> exit(status) =>
> exit(status.exitstatus || status.termsig || status.stopsig || 1)
> ```

Are we talking about SystemExit or Process::Status? I don't understand how SystemExit would work or be useful here, but I _love_ the idea of `exit($?)` serving as a shortcut for that long expression. Actually it seems as if a signal-terminated process has an exit status of 128+signal in the shell. So `exit($?)` could be a shortcut for `exit($?.exitstatus || 128 + ($?.termsig || $?.stopsig || 0))`. I think there's a real win in having the easier to use shorter expression be more robust/correct than the longer `exit($?.exitstatus)`

> It's probably even better to raise a `SignalException` on `exit(status)` if `status.signaled?`, that way the information is completely forwarded to the parent process.

Maybe... but honestly I'm not sure it would be architecturally correct for the process to fake being terminated by a signal. Also what would happen if the process was catching the signal that caused the subprocess to terminate? It seems simpler and less edge-case-prone to let the `exit` method do a regular exit.
```ruby
trap("PIPE"){ }
system("cmd1") or #terminated by PIPE
  exit($?)        #does not exit because of trap?
#we reach here even though cmd1 failed?
```



----------------------------------------
Feature #16791: Shortcut for Process::Status.exitstatus
https://bugs.ruby-lang.org/issues/16791#change-85711

* Author: 0x81000000 (/ /)
* Status: Open
* Priority: Normal
----------------------------------------
[Updated]
```
s = `csc x.cs`.sub(/.*?\n\n/m, '')
puts s if s != '';   exit $?.exitstatus if $?.exitstatus > 0
system 'mono x.exe'; exit $?.exitstatus
```
```
class Process::Status
    alias :es :exitstatus
end
```
```
s = `csc x.cs`.sub(/.*?\n\n/m, '')
puts s if s != '';   exit $?.es if $?.es > 0
system 'mono x.exe'; exit $?.es
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>