Re: Calling Shell Scripts from Ruby?

1)Is it possible to call “Shell Scripts” from ruby? Say if i
have a shell sciprt named “test.sh”, how can i call this from
ruby? Also if i can call like that,is it possible to get the
output of that script passed back to ruby?

Shell scripts fall into “any Unix command” category, so keep on reading.

2)How can i call any “Unix command” residing from a ruby program??

  1. Backquotes

result = test.sh

  1. exec(), fork/exec

exec ‘test.sh’

Process.wait fork {
exec ‘test.sh’
}

  1. popen(), popen3(), etc.

IO.popen(‘test.sh’) { |_io|
_io.readlines()
}

  1. Good old system()

system(‘test.sh’)

Read about all those facilities in the documentation to get the most out
of it.

Gennady.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs