2

I am having a problem when running a command on Windows whereas it works perfectly on Linux.

I give you the context, but this is not necessary to understand my issue: I am using gimp in batch mode.

I have a Python script callPythonFuScript.py which calls another Python script, pythonFu.py, which executes a python-fu call.

In callPythonFuScript.py, I construct the command line when I call the function inside pythonFu.py to be executed. This is the command line:

gimp-console-2.8 -idf --batch-interpreter python-fu-eval -b 'import sys;sys.path=['.']+sys.path;import pythonFu;pythonFu.myFunction("arg1","arg2","arg3") ' -b 'pdb.gimp_quit(1)'

This command works perfectly on Linux but when I try to run it on Windows, it does not work.

Error messages are:

The opening of C:\Users\myRep\sys; failed : no such file or directory
The opening of C:\Users\myRep\sys.path=['.']+sys.path; failed : no such file or directory
The opening of C:\Users\myRep\"arg1","arg2","arg3")' failed no such file or directory

I am assuming that Windows interprets characters differently than Linux. Is this correct? How can I fix this problem?

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
  • 1
    Does replacing ``'`` with ``"`` in your command line help? – Jonas Schäfer Aug 29 '12 at 17:21
  • No it does not. If you know a bit of pythonfu -b '' execute one command the first one does not work in any case ie -b 'import sys;sys.path=['.']+sys.path;importpythonFu;pythonFu.myFunction("arg1","arg2","arg3") ' but the second one works ie -b 'pdb.gimp_quit(1)' thanks for your answer Any other idea ? – user1530966 Aug 29 '12 at 17:47

1 Answers1

0

As mentioned in the comments, you are having an escaping issue between what the command prompt sees as arguments, and what is being passed as a literal string for python to eval:

-b 'import sys;sys.path=["."]+sys.path;import pythonFu;pythonFu.myFunction("arg1","arg2","arg3")'

If that still gives you errors, it is possible you might need to escape the double quotes:

-b 'import sys;sys.path=[\".\"]+sys.path;import pythonFu;pythonFu.myFunction(\"arg1\",\"arg2\",\"arg3\")'
jdi
  • 90,542
  • 19
  • 167
  • 203
  • Thanks jdi, But it still does not work, It was a good solution to avoid python making mistakes with the double quotes. But then the correct string ie -b 'import sys;sys.path=["."]+sys.path;import pythonFu;pythonFu.myFunction("arg1","arg2","arg3")' is given to windows command line and it interprets the double quotes differently from shell. I am assuming this is the problem but I do not know how to correct it. I think the first step is correct but now I have to make sur that the string giben by python is well interpreted by windows thanks again, victor – user1530966 Aug 29 '12 at 18:07
  • To figure your way around, I'd start by hacking a python script which just prints argv to stdout. You can then play around with windows command line processing by comparing your input and the scripts output. – Jonas Schäfer Aug 29 '12 at 19:17