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


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?

> Even `exec` works better than `system` & `exit`, unless you need some clean-ups.

`exec` only works as a tail-call at the end of the script. Most of the time it's not applicable:

```ruby
system(cmd1) or exit($?.exitstatus)
system(cmd2) or exit($?.exitstatus)
system(cmd3) or exit($?.exitstatus)
```

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?` :-(
I guess I'm better off sticking with `system(cmd1) or abort`

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

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