From 01898e50871fdf2f04330117258ce28b67429629 Mon Sep 17 00:00:00 2001 From: Benedek Racz Date: Mon, 13 May 2019 13:06:56 +0200 Subject: [PATCH] [FIX] Windows escape characters --- examples/cmd.py | 2 +- wexpect.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/cmd.py b/examples/cmd.py index e9583bb..e27c36d 100644 --- a/examples/cmd.py +++ b/examples/cmd.py @@ -12,7 +12,7 @@ sys.path.insert(0, wexpectPath) import wexpect # Path of cmd executable: -cmdPathes = [r'C:\\Windows\\System32\\cmd.exe', 'cmd.exe', 'cmd'] +cmdPathes = ['C:\Windows\System32\cmd.exe', 'cmd.exe', 'cmd'] cmdPrompt = '>' for cmdPath in cmdPathes: diff --git a/wexpect.py b/wexpect.py index 6670f1a..87005c2 100644 --- a/wexpect.py +++ b/wexpect.py @@ -284,7 +284,6 @@ def spawn(command, args=[], timeout=30, maxread=2000, searchwindowsize=None, log log('\t%s=%s' % (name, env[name])) if cwd: log('Working directory: %s' % cwd) - log('Spawning %s' % join_args([command] + args)) if sys.platform == 'win32': return spawn_windows(command, args, timeout, maxread, searchwindowsize, logfile, cwd, env, codepage) @@ -1413,7 +1412,6 @@ class spawn_unix (object): raise TIMEOUT ('Timeout exceeded in expect_any().') # Still have time left, so read more data c = self.read_nonblocking(self.maxread, timeout) - # c = c.decode("utf-8") freshlen = len(c) time.sleep (0.0001) incoming += c @@ -2843,7 +2841,7 @@ def join_args(args): commandline.append(arg) return ' '.join(commandline) -def split_command_line(command_line): +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 @@ -2863,7 +2861,7 @@ def split_command_line(command_line): for c in command_line: if state == state_basic or state == state_whitespace: - if c == '\\': # Escape the next character + if c == escape_char: # Escape the next character state = state_esc elif c == r"'": # Handle single quote state = state_singlequote