Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send a "Ctrl+Break" to a subprocess via pid or handler

import subprocess

proc = subprocess.Popen(['c:\windows\system32\ping.exe','127.0.0.1', '-t'],stdout=subprocess.PIPE) 
while True: 
  line = proc.stdout.readline() 
  print "ping result:", line.rstrip() 
  #sendkey("Ctrl+Break", proc)            # i need this here, this is not for terminate the process but to print a statistics result for the ping result.

If someone know how to do it, please share with me, thanks!

like image 277
user478514 Avatar asked Mar 16 '26 21:03

user478514


2 Answers

Windows? Try this:

import signal
proc.send_signal(signal.SIGBREAK)

If you meant a signal interrupt (kill -2)

import signal
proc.send_signal(signal.SIGINT)
like image 73
wim Avatar answered Mar 18 '26 13:03

wim


The Ctrl+Break keys is a SIGBREAK signal.

Under linux, you can send this signal with kill command, on Windows, this is slightly different. You can use the SendSignal tool.

like image 34
Cédric Julien Avatar answered Mar 18 '26 13:03

Cédric Julien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!