我有 python 脚本,它通过统计 R(由 PypeR)打印出长列表。这个 python 脚本工作得很好。
现在我正尝试通过 child_process 的生成功能从 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 脚本运行良好。我已经手动测试过了。
最佳答案
My python script is working perfectly. I already tested it manually.
输出清楚地表明 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()
调用会传递 startupinfo
,这仅适用于 Windows。在 Windows 上运行的带有多个参数的字符串命令在 Unix 上失败并出现 “没有这样的文件或目录”
错误。
关于node.js - 通过 spawn 从 NodeJS 调用 python 脚本时出现段错误(核心已转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22002701/