Skip to content

Commit 60fbbd4

Browse files
committed
Fix run_cmd handling in remote-run-commands
1 parent 64624ed commit 60fbbd4

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

script/remote-run-commands/customize.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,15 @@ def preprocess(i):
122122

123123
ssh_cmd_str = " ".join(ssh_cmd)
124124

125-
# Use double quotes on Windows, single quotes on Unix for better
126-
# compatibility
127-
quote_char = '"' if is_windows else "'"
128-
ssh_run_command = ssh_cmd_str + " " + user + "@" + host + \
129-
password_string + " " + quote_char + cmd_string + quote_char
125+
126+
if is_windows:
127+
safe_cmd_string = subprocess.list2cmdline([cmd_string])
128+
else:
129+
safe_cmd_string = shlex.quote(cmd_string)
130+
131+
ssh_run_command = f"{ssh_cmd_str} {user}@{host} {password_string} {safe_cmd_string}"
132+
133+
130134
env['MLC_SSH_CMD'] = ssh_run_command
131135

132136
# ---- Use sshpass if password is provided (only on Unix-like systems) ----

0 commit comments

Comments
 (0)