diff --git a/logger/logger.py b/logger/logger.py index 40aaed0..09605b3 100755 --- a/logger/logger.py +++ b/logger/logger.py @@ -523,7 +523,9 @@ def log(self, msg, cmd, cwd=None, live_stdout=False, for i in range(9)) if isinstance(cmd, list): - cmd_str = ' '.join(str(x) for x in cmd) + cmd_str = ' '.join( + "'" + str(x).replace("'", "'\"'\"'") + "'" for x in cmd + ) else: cmd_str = str(cmd) diff --git a/tests/test_logger.py b/tests/test_logger.py index e245dd7..90d79f1 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -707,3 +707,17 @@ def test_append_mode(): assert "FOR REAL" in html_text assert "111" in html_text +def test_list_commands(): + logger = Logger(stack()[0][3], Path.cwd()) + cmd = ["echo" "'"] + msg = "Make sure echo \"'\" doesn't hang" + + p = Process(target=logger.log, args=(msg, cmd)) + p.start() + p.join(1) + assert not p.is_alive() + result = logger.log("Test out commands provided as arrays", + ["echo", "'", '"', "(test)"], + return_info=True) + assert result["stdout"] == "' \" (test)\n" +