From 43c74f7f09ef6095d21e9b5d83308e3904f636a9 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Mon, 18 Nov 2019 22:34:57 -0500 Subject: Fixed bug where pipe processes were not being stopped by Ctrl-C on Windows --- cmd2/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 3155c64a..a1a0d377 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -517,10 +517,12 @@ class ProcReader(object): self._err_thread.start() def send_sigint(self) -> None: - """Send a SIGINT to the process similar to if +C were pressed.""" + """Send a SIGINT to the process similar to if +C were pressed""" import signal if sys.platform.startswith('win'): - self._proc.send_signal(signal.CTRL_C_EVENT) + # cmd2 started the Windows process in a new process group. Therefore + # a CTRL_C_EVENT can't be sent to it. Send a CTRL_BREAK_EVENT instead. + self._proc.send_signal(signal.CTRL_BREAK_EVENT) else: # Since cmd2 uses shell=True in its Popen calls, we need to send the SIGINT to # the whole process group to make sure it propagates further than the shell -- cgit v1.2.1