我正在使用ipmitool
在HP的VSP上启动串行LAN连接。我正在尝试使用字母c
发送break命令。
p = subprocess.Popen(CMD + " sol activate", shell=True, stdout=subprocess.PIPE)
#I want to send '~~B' and 'c' while watching the output.
while True:
output = p.stdout.readline()
if output:
print output
答案 0 :(得分:2)
据我所知,您需要按“c”按钮来终止您使用子进程运行的进程。使用此recipe来检测键并编写简单函数以在这样的线程内调用:
import subprocess
import os
import signal
import thread
from getch import _Getch
def kill(pro):
if _Getch()() == "c":
os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
CMD="sudo apt-get update"
p = subprocess.Popen(CMD, shell=True, stdout=subprocess.PIPE)
thread.start_new_thread(kill, (p,))
while True:
output = p.stdout.readline()
if output:
print output