From 2b4bf58e8787a5eaa4e80ed92b89b2144cde961d Mon Sep 17 00:00:00 2001
From: Martin Craig <martin.craig@eng.ox.ac.uk>
Date: Tue, 10 Jul 2018 10:53:18 +0100
Subject: [PATCH] Search for command in all configured FSL locations Previously
 this would assume $FSLDEVDIR/bin whenever $FSLDEVDIR was set even if there
 was no matching command there, but there was one in $FSLDIR

---
 fsl/utils/run.py | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/fsl/utils/run.py b/fsl/utils/run.py
index a8adb80b8..561e2ce23 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)
-- 
GitLab