From 2168ff3266be00ea213d7f42c22ff0801b41fa22 Mon Sep 17 00:00:00 2001 From: Decee1 <48594001+Decee1@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:44:03 +0200 Subject: [PATCH 1/4] Fixed/uncommented #60 Breaks support for sending Windows commands. --- wexpect/host.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wexpect/host.py b/wexpect/host.py index 72e80aa..53e06ff 100644 --- a/wexpect/host.py +++ b/wexpect/host.py @@ -231,13 +231,13 @@ def __init__(self, command, args=[], timeout=30, encoding='UTF-8', decode_errors self.args = args[:] # work with a copy self.args.insert(0, command) self.command = command - - command_with_path = shutil.which(self.command) - if command_with_path is None: - logger.warning('The command was not found or was not executable: %s.' % self.command) - raise ExceptionPexpect( - 'The command was not found or was not executable: %s.' % self.command) - self.command = command_with_path + # + # command_with_path = shutil.which(self.command) + # if command_with_path is None: + # logger.warning('The command was not found or was not executable: %s.' % self.command) + # raise ExceptionPexpect( + # 'The command was not found or was not executable: %s.' % self.command) + # self.command = command_with_path self.args[0] = self.command self.name = '<' + ' '.join(self.args) + '>' From d81ffa05738254f6465308f211efc4fd2b4c6f20 Mon Sep 17 00:00:00 2001 From: Decee1 <48594001+Decee1@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:19:20 +0200 Subject: [PATCH 2/4] Fixed #61 The EOF character is formatted differently in Windows. --- wexpect/wexpect_util.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wexpect/wexpect_util.py b/wexpect/wexpect_util.py index 7987c2d..79f9cd0 100644 --- a/wexpect/wexpect_util.py +++ b/wexpect/wexpect_util.py @@ -7,7 +7,7 @@ The command line argument parsers, and the Exceptions placed here. """ - +import platform import re import traceback import sys @@ -16,7 +16,10 @@ import signal # platform does not define VEOF so assume CTRL-D -EOF_CHAR = b'\x04' +if platform.uname().system == "Windows": + EOF_CHAR = b'^D' +else: + EOF_CHAR = b'\x04' SIGNAL_CHARS = { signal.SIGTERM: b'\x011', # Device control 1 From 9dfdf8f6d23f6bdf73b6a7b66d65148f60d5b2a1 Mon Sep 17 00:00:00 2001 From: Decee1 <48594001+Decee1@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:35:50 +0200 Subject: [PATCH 3/4] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7118ccf..2ab8caf 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,6 @@ docs/_build/ # PyBuilder target/ + +# IDE +.idea/ From a7818316df51471b8640a9fe51f2d8949fcd65a2 Mon Sep 17 00:00:00 2001 From: Decee1 <48594001+Decee1@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:38:33 +0200 Subject: [PATCH 4/4] Fixed cwd can be WindowsPathwhich causes error. --- wexpect/host.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wexpect/host.py b/wexpect/host.py index 53e06ff..fbe71af 100644 --- a/wexpect/host.py +++ b/wexpect/host.py @@ -10,6 +10,7 @@ import re import traceback import types +from pathlib import WindowsPath import psutil import signal import socket @@ -207,6 +208,9 @@ def __init__(self, command, args=[], timeout=30, encoding='UTF-8', decode_errors self.searchwindowsize = searchwindowsize self.interact_state = interact + if isinstance(self.cwd, WindowsPath): + self.cwd = str(self.cwd) + logger.info(f'Spawn started. location {os.path.abspath(__file__)}') # If command is an int type then it may represent a file descriptor.