Python subprocess throws [Errno 2] No such file or directory, 只有在远程主机上时才会产生错误

Python subprocess throws [Errno 2] No such file or directory, error generated only when it on a remote host

我 运行宁 python 2.6。只有当我通过 ssh 运行 脚本时,我才得到子进程抛出 [Errno 2] No such file or directory。

例如,如果我 运行 在机器上手动脚本,没有错误,但如果我执行 ssh hostname script.py --host hostname 它会生成错误并告诉我文件“/usr/lib64/python2.6/subprocess.py 丢失了,但事实并非如此,因为两个服务器都有该文件。

我这样写子流程调用:

p4 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

该命令仅包含一个列表。

知道为什么它在本地有效,但在远程无效吗?

解决方法是简单地将命令设置为绝对路径,例如,我需要 /sbin/mke2fs 而不是 mke2fs。