Skip to content

BF: Accept command-file with semi-colons

Paul McCarthy requested to merge bf/semi-colons-in-command-file into master

(Discovered by @flange)

Submitting an array task file with multiple commands per line is common practice, e.g. a file called commands.txt may contain:

cmd1 subject1/; cmd2 subject1/
cmd1 subject2/; cmd2 subject2/

and be submitted via fsl_sub -t commands.txt

However, when given a command file which contains multiple commands per line, where the first command does not take any arguments, fsl_sub throws an error. For example,. this file:

cmd1; cmd2 subject1/
cmd1; cmd2 subject2/

would result in an error such as:

Traceback (most recent call last):
  File "fsl_sub/utils.py", line 305, in check_command_file
    check_command(cmd)
  File "fsl_sub/utils.py", line 282, in check_command
    raise CommandError("Cannot find script/binary '{}'".format(cmd))
fsl_sub.exceptions.CommandError: Cannot find script/binary 'cmd1;'

This error originates in the fsl_sub.utils.check_command_file function, which essentially rejects command files where shutil.which(shlex.split(line)[0]) returns None, for any line in the file. In the second example above, this would resolve to shutil.which('cmd1;'), with the trailing semi-colon causing shutil.which to return None.

This PR simply ensures that trailing semi-colons are stripped from the tested command, and adds a regression test to that effect.

Merge request reports