How can I trigger a shell script and run in background (async) in Ruby?

Viewed 11676

I have a shell script named test.sh. How can I trigger the test.sh from Ruby?

I want test.sh to run as a background process, what means in Ruby it is a ansync call.

STDERR and STDOUT also need to be written to a specific file.

Any ideas?

3 Answers

I think IO.popopen also deserves a mention here. Something like this would append the output from multiple runs of the command. to stdout.log and stderr.log

open('stdout.log', 'a') { |file|
  file.puts(
      IO.popen(["./test.sh"], :err => ["stderr.log", "a"]) { |result| 
          result.read 
      }
  )
end
Related