subprocess.call 说没有这样的文件或目录,但是 os.path.isfile 说有
subprocess.call says there's no such file or directory, but os.path.isfile says there is
我有一个可执行文件,我想从 Python 运行。我定义一个指向它的路径变量:
>>> path = '/root/Cognos/Cognos/linuxi38664h/issetupnx'
我确认我实际上指向的是文件而不是目录:
>>> from os.path import isdir, isfile
>>> isdir(path)
False
>>> isfile(path)
True
但是一旦我尝试通过 subprocess.call
...运行 可执行文件...
>>> from subprocess import call
>>> call([path])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
它告诉我文件现在不存在。
我能想到的唯一可能性是可能正在找到可执行文件本身并且 运行 没问题,但是可执行文件没有说明它需要的东西(什么?)没有找到。不过,我不确定我将如何检验这个理论......或者即使它是可能的。
另一种可能是某种权限问题?虽然我想不出为什么我会有适当的权限来查看该文件,但是当我尝试 运行 宁它时突然无法看到它。
以 root 身份执行此代码:
import subprocess as sp
path = '/root/Cognos/Cognos/linuxi38664h/issetupnx'
proc = sp.Popen([path],stdin=sp.PIPE)
proc.communicate()
我应该使用 check_output
而不是 call
。然后错误将包含打印到 stdout
和 stderr
.
的所有消息
path = '/root/Cognos/Cognos/linuxi38664h/issetupnx'
from subprocess import check_output
check_output([path])
然后我会得到更详细的消息,说明加载共享库失败的原因。
我有一个可执行文件,我想从 Python 运行。我定义一个指向它的路径变量:
>>> path = '/root/Cognos/Cognos/linuxi38664h/issetupnx'
我确认我实际上指向的是文件而不是目录:
>>> from os.path import isdir, isfile
>>> isdir(path)
False
>>> isfile(path)
True
但是一旦我尝试通过 subprocess.call
...运行 可执行文件...
>>> from subprocess import call
>>> call([path])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
它告诉我文件现在不存在。
我能想到的唯一可能性是可能正在找到可执行文件本身并且 运行 没问题,但是可执行文件没有说明它需要的东西(什么?)没有找到。不过,我不确定我将如何检验这个理论......或者即使它是可能的。
另一种可能是某种权限问题?虽然我想不出为什么我会有适当的权限来查看该文件,但是当我尝试 运行 宁它时突然无法看到它。
以 root 身份执行此代码:
import subprocess as sp
path = '/root/Cognos/Cognos/linuxi38664h/issetupnx'
proc = sp.Popen([path],stdin=sp.PIPE)
proc.communicate()
我应该使用 check_output
而不是 call
。然后错误将包含打印到 stdout
和 stderr
.
path = '/root/Cognos/Cognos/linuxi38664h/issetupnx'
from subprocess import check_output
check_output([path])
然后我会得到更详细的消息,说明加载共享库失败的原因。