2011-06-23 4 views
0

私は次の行で、私のPythonプログラムからperlスクリプトを呼び出すようにしようとしています:は奇妙な行動で、その結果、パイソンからperlスクリプトを呼び出そうと

subprocess.call(r'/path/to/compute_lexrank.pl /path/to/11sent',shell=True) 

私はシェルから同じperlスクリプトを実行すると(ちょうど/path/to/compute_lexrank.pl /path/to/11sentを入力して)、それは予想通り正常に動作しますが、私はPythonプログラムからそれを実行すると、perlスクリプトが実行されますが、神秘的なエラーを与える:

Math::MatrixReal::new(): number of rows must be integer > 0 at /Users/filippo/Downloads/clairlib-core-1.08/lib//Clair/Network.pm line 1628 

私はperlスクリプトを書いてhaventので、私自身は、私がこれを修正する方法はわかりませんが、なぜ同じスクリプトがdi私はシェルやサブプロセスから実行するときにはっきりと何か?

私はMacOSX、Python 2.6を使っています(ただし、2.5、同じものを試しました)とperl 5.10。

誰でも手助けできますか?

+0

に作業ディレクトリを渡す必要があります。異なるバージョンのPerlを取得している可能性が高いです。 –

+0

どうすればいいですか? Perlスクリプトの冒頭で#!/ usr/bin/perl -wを指定しましたが、どのバージョンのperlが使用されているか確認するにはどうすればよいですか?ありがとう – Filippo

+0

'perl -e 'print" $] \ n ";''はこのトリックを行うべきです。 –

答えて

0

Perlでは、可能であれば、popensystemのリスト形式を使用することをお勧めします。 Pythonもそれらを持っているようです。私はあなたがこれを試してみるとどうなるだろうか:

helper = "/path/to/compute_lexrank.pl" 
helper_input = "/path/to/11sent" 
subprocess.call([helper, helper_input]) 
+0

私はちょうど試みたが、それはまだ同じエラーです。私は、シェルまたはPythonの内部からスクリプトを実行することの違いを理解することはできません – Filippo

0

あなたは、あなたの環境を確認subprocess.call

subprocess.call(r'/path/to/compute_lexrank.pl /path/to/11sent',shell=True,cwd="/path/to") 

If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd.

関連する問題