Python子流程Exec格式错误 [英] Python subprocess Exec format error
问题描述
很抱歉,这个问题很愚蠢.我正在使用python subprocess
语句在Ubuntu(Natty 11.04)中调用.bat文件,但是,我收到了错误消息:
Sorry if this question is dumb. I am using python subprocess
statement to call a .bat file in Ubuntu (Natty 11.04), however, I got error messages:
Traceback (most recent call last):
File "pfam_picloud.py", line 40, in <module>
a=subprocess.Popen(src2, shell=0)
File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1213, in _execute_child
raise child_exception
运行此python文件
$python pfam_picloud.py
Python代码(pfam_picloud.py)
#!/usr/bin/python
#
met="wTest.dvf"
run="run_pfam.bat"
inp="pfam_input.PFA"
import os
import stat
import shutil
import subprocess
import string
import random
# Generate a random ID for file save
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
name_temp=id_generator()
cwd=os.getcwd()
src=cwd
src1=cwd+'/'+name_temp
if not os.path.exists(src1):
os.makedirs(src1)
else:
shutil.rmtree(src1)
os.makedirs(src1)
##
shutil.copy(src+"/"+run,src1)
shutil.copy(src+"/"+met,src1)
shutil.copy(cwd+"/pfam_pi.exe",src1)
shutil.copy(src+"/"+inp,src1)
#
src2=src1+"/run_pfam.bat"
os.chdir(src1)
a=subprocess.Popen(src2, shell=0)
a.wait()
bash文件(run_pfam.bat)
#!/bin/sh
./pfam_pi.exe pfam_input.PFA
我可以在Ubuntu中成功运行此bash文件.所以我想我在Python脚本中弄乱了一些东西.有人可以给我一些建议吗?感谢您的投入.
I can successfully run this bash file in Ubuntu. So I guess, I messed up something in my Python script. Could anyone give me some suggestions? Thanks for any inputs.
文件 pfam_pi.exe
是Linux可执行文件.我在Ubuntu中编译它.抱歉造成混乱.
the file pfam_pi.exe
is a Linux executable. I compiled it in Ubuntu. Sorry for the confusion.
好吧,我现在得到了不同类型的错误.1.用#!/bin/sh
表示没有这样的文件或目录
.2.使用/bin/sh
表示 exec格式错误
.3.如果我将所有内容作为参数发送 a = subprocess.Popen(['./pfam_pi.exe','inp','src1'],shell = 0)
,它说 end线符号错误
Well, I got different types of error now.
1. With #!/bin/sh
, it said No such file or directory
.
2. With /bin/sh
, it said exec format error
.
3. If I sent everything as arguments a=subprocess.Popen(['./pfam_pi.exe', 'inp', 'src1'], shell=0)
, it said end of line symbol error
推荐答案
Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.
@Ellioh:谢谢您的评论.我发现一旦我更改了shell = 1,问题就解决了.– tao.hong
@Ellioh: Thanks for your comments. I found once I changed the shell=1, problem is solved. – tao.hong
这篇关于Python子流程Exec格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!