Skip to content

Commit

Permalink
use shlex to quote command (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackTemaki authored Mar 4, 2024
1 parent 73f648d commit 923a693
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import math
import os
import shlex
import subprocess
import time

Expand Down Expand Up @@ -84,7 +85,8 @@ def system_call(self, command, send_to_stdin=None):
:rtype: list[bytes], list[bytes], int
"""
if self.gateway:
system_command = ["ssh", "-x", self.gateway] + [" ".join(["cd", os.getcwd(), "&&"] + command)]
escaped_command = [shlex.quote(s) for s in command] # parameters need to be shell safe when sending via ssh
system_command = ["ssh", "-x", self.gateway] + [" ".join(["cd", os.getcwd(), "&&"] + escaped_command)]
else:
# no gateway given, skip ssh local
system_command = command
Expand Down Expand Up @@ -228,7 +230,7 @@ def submit_helper(self, call, logpath, rqmt, name, task_name, start_id, end_id,

sbatch_call += ["-a", "%i-%i:%i" % (start_id, end_id, step_size)]
command = '"' + " ".join(call) + '"'
sbatch_call += ["--wrap='%s'" % " ".join(call)]
sbatch_call += ["--wrap=%s" % " ".join(call)]
while True:
try:
out, err, retval = self.system_call(sbatch_call)
Expand Down

0 comments on commit 923a693

Please sign in to comment.