繁体   English   中英

CTRL-C在python中终止

[英]CTRL-C terminate in python

目前,我有一个exe文件,需要通过python传递命令。 该代码本身就可以工作。 当我将该代码段与最终程序合并后,它无法正常工作。

基本上,在使用程序shell_start上传前两个文件后(在我向其传递命令的程序中,上传是-f ),python决定使用名为shell_forward的程序跳过底部的最终上传。 使用程序shell_forward最终上传3个文件甚至无效。

因此,如果您感到困惑,我的主要问题是:为什么为什么当shell_start程序完成两个命令和文件的上传后,python shell却不允许我在其中输入任何内容? 它就像一个命令提示符窗口,在执行代码后您将无法在其中键入任何内容。

这就是为什么我觉得需要一个ctrl-c来终止上一个进程的shell_start.exe的原因,因此python可能会让我在执行后键入内容。

这是代码:

import os, time

name = raw_input("Input your name: ")
apn = raw_input("Input apn name: ")
ecid = raw_input("Input ecid name: ")
kernel = raw_input("Input kernel name: ")

os.system('shell_start.exe -f %s'%name)
time.sleep(1)
os.system('shell_start.exe -f %s'%apn)
time.sleep(1)

os.system('shell_forward.exe --imagefile myfile.img --ecid %(x)s --kernel %(y)s '% {"x" : ecid, "y" : kernel})

您可以通过更换具有更好的效果os.system与调用subprocess

子流程模块允许您生成新流程,连接到其输入/输出/错误管道,并获取其返回代码。 该模块旨在替换其他一些较旧的模块和功能,例如:

 os.system os.spawn* os.popen* popen2.* commands.* 

另请参阅PEP 324 –提出子流程模块的PEP

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM