I want to run a thread-safe piece of script in Ruby that calls an external program, then checks the exit status of that external program. What's the best way to do it? So far, I've been checking $?
, but I think I'm getting a race condition with other parts of the program.
Here's some example code:
Thread.new do
`external_program`
if $?.exitstatus == 0
# it worked.
else
# it didn't work.
end
end
Ideally, I'd do something like
Process.new(`external_program`).exitstatus
so that the exitstatus
was inextricably bound to that process, rather than the last one that happened to complete. Is there any way to do this?