From d3caa273d65a269191cd781ca44409810eec7015 Mon Sep 17 00:00:00 2001 From: Benedek Racz Date: Mon, 29 Jul 2019 11:49:39 +0200 Subject: [PATCH] [FIX] TEST of test_command_list_split, escape character change; [FIX] process killing. Based on issue: Pywin32-224 TerminateProcess Function Moved #5 --- examples/cmd.py | 2 +- tests/test_command_list_split.py | 4 ++-- wexpect.py | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/cmd.py b/examples/cmd.py index e27c36d..d3c2c12 100644 --- a/examples/cmd.py +++ b/examples/cmd.py @@ -7,7 +7,7 @@ import os here = os.path.dirname(os.path.abspath(__file__)) wexpectPath = os.path.dirname(here) -sys.path.insert(0, wexpectPath) +#sys.path.insert(0, wexpectPath) import wexpect diff --git a/tests/test_command_list_split.py b/tests/test_command_list_split.py index 9baa1c8..69c7c14 100644 --- a/tests/test_command_list_split.py +++ b/tests/test_command_list_split.py @@ -29,10 +29,10 @@ class SplitCommandLineTestCase(PexpectTestCase.PexpectTestCase): assert len(wexpect.split_command_line(r'one two')) == 2 assert len(wexpect.split_command_line(r'one two')) == 2 assert len(wexpect.split_command_line(r'one two')) == 2 - assert len(wexpect.split_command_line(r'one\ one')) == 1 + assert len(wexpect.split_command_line(r'one^ one')) == 1 assert len(wexpect.split_command_line('\'one one\'')) == 1 assert len(wexpect.split_command_line(r'one\"one')) == 1 - assert len(wexpect.split_command_line(r'This\' is a\'\ test')) == 3 + assert len(wexpect.split_command_line(r"This^' is a^'^ test")) == 3 if __name__ == '__main__': unittest.main() diff --git a/wexpect.py b/wexpect.py index 87005c2..ae5db43 100644 --- a/wexpect.py +++ b/wexpect.py @@ -1855,6 +1855,9 @@ class spawn_windows (spawn_unix, object): def kill(self, sig): """Sig == sigint for ctrl-c otherwise the child is terminated.""" + if not self.isalive(): + return + if sig == signal.SIGINT: self.wtty.sendintr() else: @@ -2108,8 +2111,8 @@ class Wtty: def terminate_child(self): """Terminate the child process.""" - - win32api.win32process.TerminateProcess(self.__childProcess, 1) + win32api.TerminateProcess(self.__childProcess, 1) + # win32api.win32process.TerminateProcess(self.__childProcess, 1) def createKeyEvent(self, char): """Creates a single key record corrosponding to @@ -2842,7 +2845,6 @@ def join_args(args): return ' '.join(commandline) def split_command_line(command_line, escape_char = '^'): - """This splits a command line into a list of arguments. It splits arguments on spaces, but handles embedded quotes, doublequotes, and escaped characters. It's impossible to do this with a regular expression, so I