python subprocess.call()“没有这样的文件或目录”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13786797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python subprocess.call() "no such file or directory"
提问by user1889259
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
with 'in' being the filepath of the file to be converted and 'out' being the path and filename to save the result to.
'in' 是要转换的文件的文件路径,'out' 是保存结果的路径和文件名。
So using Subprocess,
所以使用子进程,
subprocess.call(["fits2ndf","/media/tom_hdd/Transfer/reference.fits","/media/tom_hdd/Transfer/reference.sdf"])
this raises,
这引发,
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
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?
设置shell=TRUE(我知道这很糟糕)会产生相同的结果。不确定它是否相关,但我正在使用 tcsh。有什么建议?
Edit in response to questions
编辑回答问题
I haven't permanently set the PATH however fits2ndfis part of a package of programs which I initialize using
我没有永久设置 PATH 但是它fits2ndf是我使用初始化的程序包的一部分
% 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.
并且通常在任何目录中工作而不指定完整路径。
采纳答案by denizeren
which fits2ndfwill show you the path of fits2ndf.
which fits2ndf将向您展示 fits2ndf 的路径。
After that you can write given full path to your code and it should work.
之后,您可以编写代码的给定完整路径,它应该可以工作。
Ex:
前任:
~$ which mv
/bin/mv
My python code:
我的python代码:
import subprocess
subprocess.call(["/bin/mv","/tmp/a","/tmp/b"])
回答by Lotzki
You might want to remove the space in " /media/tom_hdd/Transfer/reference.sdf"
您可能想要删除空间 " /media/tom_hdd/Transfer/reference.sdf"
Also, try tp put everything in one string, like "fits2ndf /media/tom_hdd/Transfer/reference.fits /media/tom_hdd/Transfer/reference.sdf"
另外,尝试 tp 将所有内容放在一个字符串中,例如 "fits2ndf /media/tom_hdd/Transfer/reference.fits /media/tom_hdd/Transfer/reference.sdf"
Make sure you point to the exact direction.
确保您指向准确的方向。

