Spawnを介してNodeJSからPythonスクリプトを呼び出しながらセグメンテーションフォルト(コアダンプ)
-
20-12-2019 - |
質問
私は統計的なrを通して長いリストを印刷するPythonスクリプトを持っています(Pyperによって)。このPythonスクリプトは絶対にうまく機能しています。
今すぐ、child_processのSpawn機能を介してnodejsからこのスクリプトを実行しようとしていますが、次のエラーで失敗します。 -
Traceback (most recent call last):
File "pyper_sample.py", line 5, in <module>
r=R()
File "/home/mehtam/pyper.py", line 582, in __init__
'prog' : Popen(RCMD, stdin=PIPE, stdout=PIPE, stderr=return_err and _STDOUT or childstderr, startupinfo=info),
File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
./temp.sh: line 1: 27500 Segmentation fault (core dumped) python pyper_sample.py o1dn01.tsv cpu_overall
child process exited with code : 139
.
注:Pythonスクリプトは完全に機能しています。私はすでに手動でテストしました。
解決
Pythonスクリプトは完全に機能しています。私はすでに手動でテストしました。
出力は、OSError: No such file or directory
呼び出し中にPopen()
例外が発生したことを明確に示しています。
それはプログラムが見つからないことを意味します。
>>> from subprocess import Popen
>>> p = Popen(["ls", "-l"]) # OK
>>> total 0
>>> p = Popen(["no-such-program-in-current-path"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
.
また、コマンド全体をリストの代わりに文字列として渡す(デフォルトではshell=False
)も一般的なエラーです。
>>> p = Popen("ls -l")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
.
必ず:
- あなたの(子)プログラムは現在の
$PATH
にあります。
- 文字列 の代わりにリスト引数を使用します。
- さまざまな作業ディレクトリ、異なるユーザーなどから手動で実行された場合に機能するかどうかをテストする
注:Popen()
呼び出しは、Windowsのみのstartupinfo
を渡します。Windowsで動作するいくつかの引数を持つstringコマンドは、UNIXで"No such file or directory"
エラーで失敗します。
所属していません StackOverflow