From b6769411fd67a2af0cd8dff9216c430f4b8651c2 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 19 Aug 2015 17:02:17 +0100
Subject: [PATCH] Conditional in fsl.runTool which detects whether we are
 running as a compiled pyinstaller executable, or as a python script.

---
 fsl/__init__.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/fsl/__init__.py b/fsl/__init__.py
index d8b5cb01c..4e138a34c 100644
--- a/fsl/__init__.py
+++ b/fsl/__init__.py
@@ -394,11 +394,26 @@ def runTool(toolName, args, **kwargs):
     in a separate process. Returns the process exit code.
     """
 
+
     args = [toolName] + args
-    args = [sys.executable, '-c', 'import fsl; fsl.main()'] + args
+    
+    # If we are running from a compiled fsleyes
+    # executable, we need to prepend command line
+    # arguments with 'cmd' - see the wrapper script
+    # created by:
+    #
+    # https://git.fmrib.ox.ac.uk/paulmc/fslpy_build/\
+    #     blob/master/build_osx_app.sh
+    if getattr(sys, 'frozen', False):
+        args = [sys.executable, 'cmd'] + args
+
+    # Otherwise we are running
+    # through a python interpreter
+    else:
+        args = [sys.executable, '-c', 'import fsl; fsl.main()'] + args
 
     log.debug('Executing {}'.format(' '.join(args)))
-
+    
     return subprocess.call(args, **kwargs)
 
 
-- 
GitLab