簡體   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