Python 2.7 无法使用子进程执行py文件
我在Windows7中使用Python2.7。 当我使用subprocess执行py文件时,不会发生错误,subprocess中会返回“success”,但该文件(flashimage.py)实际上没有执行Python 2.7 无法使用子进程执行py文件,python-2.7,Python 2.7,我在Windows7中使用Python2.7。 当我使用subprocess执行py文件时,不会发生错误,subprocess中会返回“success”,但该文件(flashimage.py)实际上没有执行 def program(self): self.blueflashcmd = os.path.join('python' + self.TESTENGINEDIR, 'flashimage.py') args = [self.blueflashcmd]
def program(self):
self.blueflashcmd = os.path.join('python' + self.TESTENGINEDIR,
'flashimage.py')
args = [self.blueflashcmd]
output = self.my_check_output(args)
if 'Success' not in output:
error_msg = output.strip().split('\n')[-1]
raise ProgramError(error_msg)
def my_check_output(self, args, retry=False):
start = time.clock()
p = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, startupinfo=suinfo)
output = ''
while p.poll() is None:
part = p.stdout.read()
output += part
time.sleep(0.1)
part = p.stdout.read()
output += part
if p.returncode != 0:
raise ProgramError("RETURN %d: %s" % (p.returncode,
output.strip()))
if not output.strip():
if not retry:
return self.my_check_output(args, retry=True)
else:
raise ProgramError('ERROR')
return output