OSError:[Errno 2]在Python中使用subprocess.Popen时,没有这样的文件或目录

OSError:[Errno 2]在Python中使用subprocess.Popen时,没有这样的文件或目录,python,subprocess,Python,Subprocess,当我使用subprocess.Popen(在ubuntu中)时,Python有一个问题。我有这样一个代码: # This line is just to check if the path are right. # I can delete this first Popen but I get always the same error. out = subprocess.Popen(["ls"], cwd='/home/user/Desktop/', stdout=subprocess

当我使用subprocess.Popen(在ubuntu中)时,Python有一个问题。我有这样一个代码:

# This line is just to check if the path are right. 
# I can delete this first Popen but I get always the same error.
out = subprocess.Popen(["ls"], cwd='/home/user/Desktop/',
   stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]

print out

# This line doesn't work
out = subprocess.Popen(["mri_info", "--vox2ras", "orig.mgz"], 
    cwd='/home/user/Desktop/',
    stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]

print out
第一个Popen运行得很好,但第二个Popen没有。它给了我一个错误:

OSError: [Errno 2] No such file or directory

我确信路径是正确的,文件orig.mgz在该目录中,但是。。。它不起作用。有人能帮我吗?

试试绝对路径。如果ubuntu中的绝对路径类似于/home/user/directory/i,我正在使用它来显示文档“如果cwd不是None,则在执行之前,子目录的当前目录将更改为cwd。请注意,搜索可执行文件时不考虑此目录,因此不能指定程序相对于cwd的路径。“如果您实际使用的是绝对路径
/home/user/directory/mri\u info
,请编辑您的问题以显示它。我怀疑您没有。我实际使用的路径是
/home/user/Desktop/
(对于这两个子进程.Popen),事实仍然是错误消息可能是因为找不到
mri\u info
,而不是因为找不到
orig.mgz
文件。再次阅读评论。