Fix argument lexer in ProcessLogger, replace it with shlex standard python module.
authorEdouard Tisserant <edouard@beremiz.fr>
Tue, 20 Feb 2024 11:37:54 +0100
changeset 3892 1675b5533e9e
parent 3891 0f375805097a
child 3893 5b2f3a915a43
Fix argument lexer in ProcessLogger, replace it with shlex standard python module.
util/ProcessLogger.py
--- a/util/ProcessLogger.py	Tue Feb 20 11:34:28 2024 +0100
+++ b/util/ProcessLogger.py	Tue Feb 20 11:37:54 2024 +0100
@@ -28,6 +28,7 @@
 import subprocess
 import ctypes
 import time
+import shlex
 from threading import Timer, Lock, Thread, Semaphore, Condition
 import signal
 
@@ -82,16 +83,9 @@
         self.logger = logger
         if not isinstance(Command, list):
             self.Command_str = Command
-            self.Command = []
-            for i, word in enumerate(Command.replace("'", '"').split('"')):
-                if i % 2 == 0:
-                    word = word.strip()
-                    if len(word) > 0:
-                        self.Command.extend(word.split())
-                else:
-                    self.Command.append(word)
-        else:
-            self.Command = [x if type(x)==str else x.decode() for x in Command]
+            self.Command = shlex.split(Command)
+        else:
+            self.Command = Command
             self.Command_str = subprocess.list2cmdline(self.Command)
 
         fsencoding = sys.getfilesystemencoding()