Issue #16791 has been updated by nobu (Nobuyoshi Nakada).


Dan0042 (Daniel DeLorme) wrote in #note-6:
> nobu (Nobuyoshi Nakada) wrote in #note-4:
> > It is not a good idea to compare `exitstatus` with 0 from the point of portability.
> 
> Can I ask why that is? 0 is success and non-0 is failure; I don't know of any system where things are different. What is the portability issue?

I don't know such systems actually too, just only the rationale of `EXIT_SUCCESS` and `EXIT_FAILURE` in the C standard.

> Although thanks to your comment I've realized that exitstatus is nil if the process exited because of a signal. That means the code above is equivalent to `exit(0)` if the command failed because of `$?.signaled?` :-(

That executes `exit(nil)` and results in `TypeError`.

> I guess I'm better off sticking with `system(cmd1) or abort`

Yes, it's a good alternative.

It may be acceptable to let `exit` accept a `SystemExit` instance though.

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

* 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>