2012-05-03 56 views
1

我必须在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 

如果我改变shell=1,有没有投诉,但没有输出文件要么产生。

我已经检查此文件的使用file filename.exe 它返回的类型:

文件名.exe:ELF 64位LSB的可执行文件,X86-64,版本1(SYSV) 动态链接(使用共享库),为GNU/Linux 2.6.9,不 剥离

所以是有可能在Ubuntu使用subprocess.Popen称呼它?

+1

你试图在32位主机上运行64位二进制文​​件吗?你可以显示'uname -a'的输出吗? –

+0

这看起来像我的Ubuntu是32位,这可能会导致我的问题..我可以知道什么是uname -a? –

+0

这是一个打印有关主机信息的命令,包括操作系统,主机名,内核版本,内核编译时间和体系结构(从中可以知道它是否是a)。在我的32位笔记本电脑上,它打印出“Linux redance 2.6.26-2-686#1 SMP Thu Jan 27 00:28:05 UTC 2011 i686 GNU/Linux',而在我的64位服务器上打印'Linux red 2.6。 32-5-amd64#1 SMP Mon Jan 16 16:22:28 UTC 2012 x86_64 GNU/Linux'。 –

回答

3

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

+0

它没有抱怨喂/ bin/false,所以它看起来像我的exe是错误的。另外,shell = 0和shell = 1有什么区别。谢谢 –

+0

如果shell = 1,那么你并没有执行一个文件,你将一个字符串传递给你的shell来评估(.e.g“ls -la〜/”) – imichaelmiers