diff --git a/fsl/utils/run.py b/fsl/utils/run.py index a8adb80b879a198485970284d562ef6064c96d96..561e2ce2322e5c1ff1cc16d0f06ac7e48576cb05 100644 --- a/fsl/utils/run.py +++ b/fsl/utils/run.py @@ -337,27 +337,38 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args): def runfsl(*args, **kwargs): - """Call a FSL command and return its output. This function simply prepends - ``$FSLDIR/bin/`` to the command before passing it to :func:`run`. + """Call a FSL command and return its output. + + This function searches for the command in the following + locations (ordered by priority): + + 1. ``FSL_PREFIX`` + 2. ``$FSLDEVDIR/bin`` + 3. ``$FSLDIR/bin`` + + If found, the full path to the command is then passed to :func:`run`. """ - - prefix = None + prefixes = [] if FSL_PREFIX is not None: - prefix = FSL_PREFIX - elif fslplatform.fsldevdir is not None: - prefix = op.join(fslplatform.fsldevdir, 'bin') - elif fslplatform.fsldir is not None: - prefix = op.join(fslplatform.fsldir, 'bin') - else: + prefixes.append(FSL_PREFIX) + if fslplatform.fsldevdir is not None: + prefixes.append(op.join(fslplatform.fsldevdir, 'bin')) + if fslplatform.fsldir is not None: + prefixes.append(op.join(fslplatform.fsldir, 'bin')) + + if not prefixes: raise FSLNotPresent('$FSLDIR is not set - FSL cannot be found!') - args = _prepareArgs(args) - args[0] = op.join(prefix, args[0]) + args = _prepareArgs(args) + for prefix in prefixes: + cmdpath = op.join(prefix, args[0]) + if op.isfile(cmdpath): + args[0] = cmdpath + break return run(*args, **kwargs) - def wait(job_ids): """Proxy for :func:`.fslsub.wait`. """ return fslsub.wait(job_ids)