Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 调用子进程_Python_Ubuntu - Fatal编程技术网

Python 调用子进程

Python 调用子进程,python,ubuntu,Python,Ubuntu,我必须在Ubuntu中调用一个可执行文件。。。刚刚学习了如何在windows中使用subprocess.Popen来实现这一点。现在,我需要在Ubuntu中重复这个步骤 我使用了以下Python命令: a=subprocess.Popen("filename.exe",shell=0) 回报是 Traceback (most recent call last): File "/untitled0.py", line 29, in <module> a=subproces

我必须在Ubuntu中调用一个可执行文件。。。刚刚学习了如何在windows中使用
subprocess.Popen
来实现这一点。现在,我需要在Ubuntu中重复这个步骤

我使用了以下Python命令:

a=subprocess.Popen("filename.exe",shell=0)
回报是

Traceback (most recent call last):
  File "/untitled0.py", line 29, in <module>
    a=subprocess.Popen("filename.exe",shell=0)
  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 8] Exec format error
回溯(最近一次呼叫最后一次):
文件“/untitled0.py”,第29行,在
a=subprocess.Popen(“filename.exe”,shell=0)
文件“/usr/lib/python2.7/subprocess.py”,第679行,在__
错误读取,错误写入)
文件“/usr/lib/python2.7/subprocess.py”,第1249行,在执行子进程中
引发子对象异常
OSError:[Errno 8]Exec格式错误
如果我更改
shell=1
,则不会有投诉,但也不会生成输出文件

我已使用
file filename.exe
它返回:

filename.exe:ELF 64位LSB可执行文件,x86-64,版本1(SYSV), 动态链接(使用共享libs),适用于GNU/Linux 2.6.9,而不是 剥去


那么,在Ubuntu中使用
subprocess.Popen
调用它是否可行呢?

快速阅读python文档,看起来你做的事情是正确的,所以。如何尝试执行say/bin/false,这应该是系统上已知的正在工作的exe。如果这样做有效,那么您的exe可能是错误的(在32位系统上可能是64位的)

您是否正在尝试在32位主机上运行64位二进制文件?你能展示一下uname-a的输出吗?看起来我的Ubuntu是32位的,这可能会引起我的问题。。我可以知道什么是uname-a吗?它是一个命令,用于打印有关主机的信息,包括操作系统、主机名、内核版本、内核编译时间和体系结构(从中可以判断它是否是一个主机)。在我的32位笔记本电脑上打印
Linux radiance 2.6.26-2-686#1 SMP周四1月27日00:28:05 UTC 2011 i686 GNU/Linux
,而在我的64位服务器上打印
Linux red 2.6.32-5-amd64#1 SMP周一1 UTC 2012年1月16日16:22:28 x86 GNU/Linux
。感谢您的解释。我说Linux th VirtualBox 3.2.0-24-generic-pae#37 Ubuntu SMP周三4月25日10:47:59 UTC 2012 i686 i686 i386 GNU/Linux,所以我应该尝试一个32位的exe文件。是的,这是一个32位系统。它没有通过输入/bin/false来抱怨,所以我的exe似乎是错误的。此外,shell=0和shell=1之间的区别是什么。ThanksIf shell=1,您不是在执行文件,而是在将字符串传递给要求值的shell(.e.g“ls-la~/”)