python subprocess.call() “no such file or directory”

守給你的承諾、 提交于 2019-12-19 05:23:07

问题


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.

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?


Edit in response to questions

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.


回答1:


which fits2ndf will show you the path of fits2ndf.

After that you can write given full path to your code and it should work.

Ex:

~$ which mv
/bin/mv

My python code:

import subprocess

subprocess.call(["/bin/mv","/tmp/a","/tmp/b"])



回答2:


You might want to remove the space in " /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"

Make sure you point to the exact direction.



来源:https://stackoverflow.com/questions/13786797/python-subprocess-call-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!