Python子进程抛出[Errno 2]没有这样的文件或目录,仅当它在远程主机上时才会生成错误 [英] Python subprocess throws [Errno 2] No such file or directory, error generated only when it on a remote host

查看:88
本文介绍了Python子进程抛出[Errno 2]没有这样的文件或目录,仅当它在远程主机上时才会生成错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行python 2.6.我正在让子进程抛出[Errno 2]仅当我通过ssh运行脚本时才没有这样的文件或目录.

I'm running python 2.6. I'm getting the subprocess throws [Errno 2] No such file or directory only when I run the script via ssh.

例如,如果我在计算机上手动运行脚本,则没有错误,但是如果我使用ssh主机名script.py --host hostname,它将生成错误并告诉我文件"/usr/lib64/python2.6/subprocess" .py丢失了,但是事实并非如此,因为两台服务器都具有该文件.

For example, if I run the script manually on the machine, there are no errors, but if I do ssh hostname script.py --host hostname it generates the error and tells me that File "/usr/lib64/python2.6/subprocess.py is missing, but that's not true as both servers have that file.

我已经这样写了子流程调用:

I've written the subprocess call like this:

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

该命令仅包含一个列表.

The command just contains a list.

有什么想法为什么可以在本地而不是在远程工作?

Any ideas why it works locally, but not remotely?

推荐答案

解决方案是将命令设置为绝对路径,例如,我需要/sbin/mke2fs而不是mke2fs.

The solution for this was to simply have the command set to the absolute path, for example, instead of mke2fs, I needed /sbin/mke2fs.

这篇关于Python子进程抛出[Errno 2]没有这样的文件或目录,仅当它在远程主机上时才会生成错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆