昨天,我编写并运行了一个python script,它使用构成.sh脚本及其参数的string命令subprocess.Popen(command.split())来执行subprocess.Popen(command.split())。直到昨天,这个剧本还很好用。今天,我运行了相同的脚本,现在我不断地碰到这个错误。
p=subprocess.Popen(shell_command.split())
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=True不起作用,因为我的shell脚本调用另一个shell脚本,在此之前必须设置一些环境才能运行该脚本。我被困在这里面了。我只要重启一次系统。我正在使用ubuntu 12.04
编辑:
import subprocess
import os
import sys
arg1=sys.argv[1]
arg2=sys.argve[2]
shell_command = 'my_path/my_shell.sh ' + arg1 + ' '+ arg2
P = subprocess.Popen(shell_command.split())
P.wait()my_shell.sh:
arg1=$1
arg2=$2
cd $TOP
setup the environment and run shell script
build the kernel ...
execute shell command .....发布于 2015-05-30 21:02:08
我通过将这一行放在被调用的shell脚本的顶部来解决这个问题:
#!/bin/sh
这将确保系统在运行脚本时始终使用正确的解释器。
发布于 2015-01-05 10:12:58
下面的陈述对我有效
subprocess.Popen(['sh','my_script.sh'])
发布于 2014-11-07 19:24:13
错误消息表明外部程序不是有效的可执行文件。
https://stackoverflow.com/questions/26807937
复制相似问题