python subprocess.call() quot;no such file or directoryquot;(python subprocess.call() “没有这样的文件或目录)
问题描述
我在模块上发现了一些问题,但更常见的问题似乎是我认为我已经管理的参数列表正确(最终)
I've found a few questions on the module but the more common problem seems to be getting the argument list right which I think I have managed (eventually)
我正在尝试运行一个程序,该程序需要在命令行中输入这样的输入,
I am trying to run a program that expects an input like this in the command line,
fits2ndf in out
'in' 是要转换的文件的文件路径,'out' 是保存结果的路径和文件名.
with 'in' being the filepath of the file to be converted and 'out' being the path and filename to save the result to.
所以使用子进程,
subprocess.call(["fits2ndf","/media/tom_hdd/Transfer/reference.fits","/media/tom_hdd/Transfer/reference.sdf"])
这引发了,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
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=TRUE
(我知道这是不好的)会产生相同的结果.不确定它是否相关,但我正在使用 tcsh.有什么建议吗?
Setting shell=TRUE
(which I know is bad) produces the same result. Not sure if it is relevant but I am using tcsh. Any suggestions?
根据问题进行编辑
我没有永久设置 PATH,但是 fits2ndf
是我使用初始化的程序包的一部分
I haven't permanently set the PATH however fits2ndf
is part of a package of programs which I initialize using
% tcsh
% setenv STARLINK_DIR /home/tomq/star-kapuahi
% source $STARLINK_DIR/etc/login
% source $STARLINK_DIR/etc/cshrc
并且通常在任何目录中都可以在不指定完整路径的情况下工作.
and normally works from within any directory without specifying the full path.
推荐答案
whichfits2ndf
会告诉你fits2ndf的路径.
which fits2ndf
will show you the path of fits2ndf.
之后,您可以编写代码的完整路径,它应该可以工作.
After that you can write given full path to your code and it should work.
例如:
~$ which mv
/bin/mv
我的python代码:
My python code:
import subprocess
subprocess.call(["/bin/mv","/tmp/a","/tmp/b"])
这篇关于python subprocess.call() “没有这样的文件或目录"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:python subprocess.call() “没有这样的文件或目录"


基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01