1

I am using ipmitool to start an serial over lan connection on the VSP of an HP. I am trying to send the break command with the letter c.

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
1
  • you mean you want to interrupt the process? Commented Feb 7, 2017 at 13:40

1 Answer 1

2

As far as I can understand you want pressing "c" button to kill the process that you run with subprocess. Use this recipe to detect key and write simple function to call inside a thread like this:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.