0

IO.popen("command").readlines を使用してそのコマンドの STDOUT を取得する宿題の短いファイルを完成させました。ただし、Ruby ファイルをラップするシェル スクリプトを作成する必要があります。問題はありませんが、シェル スクリプトに入れると readlines がハングします。

ruby script.rb foo example > example.out

これは動作します

script.sh foo example >example.out

これは readlines でハングアップします。ruby script.rbscript.sh に含まれるすべてです。

4

1 に答える 1

1

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

于 2009-10-14T06:53:56.197 に答える