diff --git a/snakemake/executors/__init__.py b/snakemake/executors/__init__.py index b3e758591..a12aef43b 100644 --- a/snakemake/executors/__init__.py +++ b/snakemake/executors/__init__.py @@ -1215,7 +1215,7 @@ def job_status(job, valid_returns=["running", "success", "failed"]): if self.sidecar_vars: env["SNAKEMAKE_CLUSTER_SIDECAR_VARS"] = self.sidecar_vars ret = subprocess.check_output( - "{statuscmd} {jobid}".format( + "{statuscmd} '{jobid}'".format( jobid=job.jobid, statuscmd=self.statuscmd ), shell=True, diff --git a/tests/test_cluster_statusscript_multi/Snakefile.nonstandard b/tests/test_cluster_statusscript_multi/Snakefile.nonstandard new file mode 100644 index 000000000..52c456c3e --- /dev/null +++ b/tests/test_cluster_statusscript_multi/Snakefile.nonstandard @@ -0,0 +1,13 @@ +from snakemake import shell + +envvars: + "TESTVAR" + + + +rule all: + input: 'output.txt' + +rule compute: + output: 'output.txt' + shell: 'touch {output}' diff --git a/tests/test_cluster_statusscript_multi/expected-results/output.txt b/tests/test_cluster_statusscript_multi/expected-results/output.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_cluster_statusscript_multi/sbatch b/tests/test_cluster_statusscript_multi/sbatch new file mode 100755 index 000000000..39b6e88da --- /dev/null +++ b/tests/test_cluster_statusscript_multi/sbatch @@ -0,0 +1,8 @@ +#!/bin/bash +echo `date` >> sbatch.log +tail -n1 $1 >> sbatch.log +# simulate printing of job id by a random number plus the name +# of the cluster +echo "$RANDOM;name-of-cluster" +cat $1 >> sbatch.log +sh $1 diff --git a/tests/test_cluster_statusscript_multi/status.sh b/tests/test_cluster_statusscript_multi/status.sh new file mode 100755 index 000000000..9e3eb1724 --- /dev/null +++ b/tests/test_cluster_statusscript_multi/status.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# The argument passed from sbatch is "jobid;cluster_name" + +arg="$1" +jobid="${arg%%;*}" +cluster="${arg##*;}" + +echo success diff --git a/tests/tests.py b/tests/tests.py index 63abd0edc..329162eb2 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -166,6 +166,17 @@ def test_cluster_cancelscript_nargs1(): assert len(scancel_lines[1].split(" ")) == 2 +@skip_on_windows +def test_cluster_statusscript_multi(): + os.environ["TESTVAR"] = "test" + run( + dpath("test_cluster_statusscript_multi"), + snakefile="Snakefile.nonstandard", + cluster="./sbatch", + cluster_status="./status.sh", + ) + + def test15(): run(dpath("test15"))