From: Edwin van Leeuwen Date: 2006-05-03T20:53:40+09:00 Subject: Re: Calling Shell Scripts from Ruby ? Dinesh Umanath wrote: > Hi Shev, > > Thank for the reply. But my requirement is that i have to call the shell > scripts or Unix Commands from Ruby itself, rather than from IRB ?? > Because i will be basicall invoking the ruby from Web (Rails)? > > Thank You.. >> 1) Start irb. Then do this: >> 2) cmd_result = `ls` >> >> # => "acoc-0.7.1.tar.bz2\n (and much more but i edited it out) >> >> 3) puts cmd_result.class # => String >> >> 4) Create a shell file such as test.sh, with content like >> echo "This is a test" >> >> 5) `sh test.sh` >> Thx shev for being more verbose, that was what I was hinting at. At heart invoking sh test.sh is the same as invoking any (unix)command and you can do that by putting the command between `` As you can see from irb this will also give you the output of the file. There is no difference between doing something in irb and in a normal ruby file, except that irb gives you immediate feedback for testing purposes. So you can just put `a_unix_command` in your ruby file to execute commands. (Where you replace a_unix_command by the actual command/script you want to execute.) Edwin -- Posted via http://www.ruby-forum.com/.