How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?
Don't forget the spawn
command to create a background process to execute the specified command. You can even wait for its completion using the Process
class and the returned pid
:
pid = spawn("tar xf ruby-2.0.0-p195.tar.bz2")
Process.wait pid
pid = spawn(RbConfig.ruby, "-eputs'Hello, world!'")
Process.wait pid
The doc says: This method is similar to #system
but it doesn't wait for the command to finish.