views:

382

answers:

1

I finished my short file for a homework assignment which uses IO.popen("command").readlines to grab the STDOUT of that command. However, I need to write a shell script to wrap my ruby file in. No problem, but somehow putting it in the shell script makes readlines hang.

ruby script.rb foo example > example.out

this works

script.sh foo example >example.out

this hangs on readlines. ruby script.rb is all that script.sh contains.

+1  A: 

Looks like you forgot to pass your arguments to the ruby command. You may also be failing to specify an interpreter

script.sh

#!/bin/sh
ruby script.rb "$@"

Alternatively you could just add #!/usr/bin/ruby to the top of script.rb and make it executable (chmod +x script.rb). It's not a shell script. But it's generally the preferred way of executing a script in an interpretive language.

Once that's done you can run it with

./script.rb

EmFi
should be /usr/bin/ruby (without "e" in user)
gustavgans
Thanks for pointing that out. Sometimes the fingers are quicker than the brain.
EmFi
alternatively, /usr/bin/env ruby
perimosocordiae