Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel.system() exit status doesn't seem to be stored at $? #2141

Open
wilsonehusin opened this issue Jun 18, 2020 · 0 comments · May be fixed by #2226
Open

Kernel.system() exit status doesn't seem to be stored at $? #2141

wilsonehusin opened this issue Jun 18, 2020 · 0 comments · May be fixed by #2226

Comments

@wilsonehusin
Copy link

Setup

$ ruby --version
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ pry --version
Pry version 0.13.1 on Ruby 2.7.1

Expected

In a file called system_call_exit_status.rb, I have the following:

system "exit 1"
puts "-- $? => #{$?}"
puts "-- $?.success? => #{$?.success?}"

which outputs

$ ruby system_call_exit_status.rb
-- $? => pid 94141 exit 1
-- $?.success? => false

The example above seem to demonstrate that system writes the exit status to $?, as described in documentation

Similar output can be seen by invoking pry on the file, i.e.

$ pry system_call_exit_status.rb
-- $? => pid 94141 exit 1
-- $?.success? => false

I would expect pry REPL to behave the same.

Actual

Unfortunately, the actual output from pry REPL seem to be different:

[1] pry(main)> system "exit 1"
=> false
[2] pry(main)> puts "-- $? => #{$?}"
-- $? => pid 94155 exit 0
=> nil
[3] pry(main)> puts "-- $?.success? => #{$?.success?}"
-- $?.success? => true
=> nil

Is this expected? I'm guessing pry REPL session overrides $? on calls to system, because using backticks seem to show accurate behavior, i.e.

[1] pry(main)> `exit 1`
=> ""
[2] pry(main)> puts "-- $? => #{$?}"
-- $? => pid 94156 exit 1
=> nil
[3] pry(main)> puts "-- $?.success? => #{$?.success?}"
-- $?.success? => false
=> nil
h7kayama added a commit to h7kayama/pry that referenced this issue Nov 26, 2021
h7kayama added a commit to h7kayama/pry that referenced this issue Nov 26, 2021
@h7kayama h7kayama linked a pull request Nov 26, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant