Actions
Bug #20514
closedOpen3#capture3 does not receive correct exit code from Heroku but Kernel#system does
Status:
Feedback
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Description
Heroku has a command-line switch for returning the exit code from a detached process to the calling terminal via their CLI. However, Open3 doesn't appear to receive this exit code properly:
irb(main):007> command = 'heroku run "rails db:migrate:status | grep \"down \"" --exit-code -a remote_app'
=> "heroku run \"rails db:migrate:status | grep \\\"down \\\"\" --exit-code -a remote_app"
irb(main):008> params = {}
=> {}
irb(main):009> stdout_str, stderr_str, status = Open3.capture3(command, params)
=> ["", "Running rails db:migrate:status | grep \"down \" on remote_app... provisioning, run.2070 (Shield-M)\n", #<Process::Status: pid 34912 exit 0>]
irb(main):010> status
=> #<Process::Status: pid 34912 exit 0>
irb(main):011> status.exitstatus
=> 0
In this case, since I know that there are no migrations with status "down", grep should return an exit code of 1, not 0. Running the same command with system gives the expected result:
irb(main):025> command = 'heroku run "rails db:migrate:status | grep \"down \"" --exit-code -a remote_app'
=> "heroku run \"rails db:migrate:status | grep \\\"down \\\"\" --exit-code -a remote_app"
irb(main):026> res = system(command)
Running rails db:migrate:status | grep "down " on ⬢ remote_app... provisioning, run.9202 (Shield-M)
# intermediate output snipped
› Error: Process exited with code 1
› Code: 1
=> false
Switching "up" for "down" in the above grep statement yields true
for exit code 0 when called with Kernel#system.
This doesn't happen locally, but since Kernel#system gives the right results but Open3#capture3 does not, I don't think the problem is on Heroku's end.
Actions
Like0
Like0Like1Like0Like0