Passing path variable from powershell x86 to python doesn't work

1

I have been routinely running a python script using Windows PowerShell. I have recently made changes to the code and now it doesn't seem to work. To elaborate, there is an issue with the variable 'root_dir_path' being passed from powershell to python.

In powershell I run the following which should define the path variable 'root_dir_path':

PS Z:\> C:\Hyapp\FIJI-W~1.52P\Fiji.app\ImageJ-win64.exe --ij2 --headless -- 
console --run D:\Cabut- 
PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py 
"root_dir_path='D:\Cabut- 
PWP1-preliminary-data\All\Stitching'"

Please could somebody tell me why it subsequently doesn't work?

Particularly giving the following error:

    NameError: name 'root_dir_path' is not defined

And the line in question (361) is when I am trying to call the main() function:

main(root_dir_path)

I get the following in powershell:

PS Z:\> C:\Hyapp\FIJI-W~1.52P\Fiji.app\ImageJ-win64.exe --ij2 --headless --console --run D:\Cabut- 
PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py "root_dir_path='D:\Cabut- 
PWP1-preliminary-data\All\Stitching'"
PS Z:\> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed 
in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be 
removed in a future release
tammikuuta 31, 2020 5:21:04 IP. java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows 
RegCreateKeyEx(...) returned error code 5.
[WARNING] Unmatched input: root_dir_path
[ERROR] Traceback (most recent call last):
File "D:\Cabut-PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py", line 362, 
in <module>
main(root_dir_path)
NameError: name 'root_dir_path' is not defined

    at org.python.core.Py.NameError(Py.java:290)
    at org.python.core.PyFrame.getname(PyFrame.java:257)
    at org.python.pycode._pyx0.f$0(D:\Cabut-PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py:362)
    at org.python.pycode._pyx0.call_function(D:\Cabut-PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:171)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1614)
    at org.python.core.__builtin__.eval(__builtin__.java:497)
    at org.python.core.__builtin__.eval(__builtin__.java:501)
    at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
python-3.x
powershell
powershell-2.0
asked on Stack Overflow Jan 31, 2020 by jmorrr • edited Feb 3, 2020 by jmorrr

1 Answer

0

I figured it out finally.

The call for the main function in the python script also had the following line above:

#@String root_dir_path
main(root_dir_path)

This #@String root_dir_path seemed to be necessary for the variable to pass correctly from powershell. When I had reformatted automatically in pycharm a space was added as it thought this line was a simple comment:

# @String root_dir_path

This seemed to cause the error. Getting rid of the space allowed it to work once more.

answered on Stack Overflow Feb 5, 2020 by jmorrr

User contributions licensed under CC BY-SA 3.0