Gimp-Forum.net
GIMP python script from command line - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: GIMP python script from command line (/Thread-GIMP-python-script-from-command-line)



GIMP python script from command line - ghoul fool - 12-06-2020

Hi, first time caller - so go easy on me. Smile

I'm running GIMP 2.10.18 on Win7, trying to run a script from the command line using:

Code:
cd %~dp0
"D:\GIMP2\bin\gimp-2.10.exe" -idfs --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import myscript;myscript.run('./images')" -b "pdb.gimp_quit(1)"

The error I get is simply:
Code:
batch command experienced an execution error
(Type any character to close this window)


I tried to make the errors verbose with 
Code:
sys.stderr = open('D:/temp/python-fu-output.txt','a')
sys.stdout=sys.stderr

...only to no avail.

I'm used to running and writing scripts for Photoshop so this is all new to me. Thanks for any help.


RE: GIMP python script from command line - rich2005 - 12-07-2020

I will bump this up incase it gets forgotten Wink Personally I avoid using Gimp on command line, using ImageMagick or Gimp with GUI BIMP instead.

However these might help until one of the clever guys comes along.

This I have bookmarked, a post from Ofnuts: https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-command-line

and this one more advice http://gimpchat.com/viewtopic.php?f=9&t=15024

There might be something there that helps.


RE: GIMP python script from command line - ghoul fool - 12-07-2020

I'm tied to doing this as a Gimp Script (which was working on a Mac earlier in the year).

Using Xeniod's example on Stackoverflow I realised that my batch file needed the /d to run from the same file as the batch file.

cd /d %~dp0

However, it now says:
batch command executed successfully

without processing (photocopy/cartoon filter) to the image.

Further investigations suggest that the folder (from which the batch file and image live) and sub folder are being changed to "read only"


RE: GIMP python script from command line - ghoul fool - 12-07-2020

(12-07-2020, 12:11 PM)ghoul fool Wrote: I'm tied to doing this as a Gimp Script (which was working on a Mac earlier in the year).

Using Xeniod's example on Stackoverflow I realised that my batch file needed the /d to run from the same file as the batch file.

cd /d %~dp0

However, it now says:
batch command executed successfully

without processing (photocopy/cartoon filter) to the image.



RE: GIMP python script from command line - Ofnuts - 12-08-2020

Do you get any output from the Python code (print statements)? Otherwise see here for some hints.

PS: I don't see how Gimp or the Python code could change the status of the directory. OTOH IIRC on recent Windows unknown apps are not always allowed to write files, so maybe you need to give Gimp some privileges.


RE: GIMP python script from command line - ghoul fool - 12-08-2020

(12-08-2020, 07:28 AM)Ofnuts Wrote: Do you get any output from the Python code (print statements)? Otherwise see here for some hints.

PS: I don't see how Gimp or the Python code could change the status of the directory. OTOH IIRC on recent Windows unknown apps are not always allowed to write files, so maybe you need to give Gimp some privileges.

I've reinstalled as Admin, and I'm able to create a script create a folder (yay!  Big Grin)

Code:
def make_dir():

 mainDir = "D:\\temp\\images"
 folder = "spoon"
 fname = os.path.join(mainDir, folder)

 # make a directory
 os.mkdir(fname)

 msg = "Make a " + folder + " directory!! " + "\n"
 gimp.message(msg)

Now the main thing is trying to work out
(a) how to get some sort of error log feedback and (b) which line/s doesn't it like.



RE: GIMP python script from command line - Ofnuts - 12-08-2020

(12-08-2020, 09:13 AM)ghoul fool Wrote:
(12-08-2020, 07:28 AM)Ofnuts Wrote: Do you get any output from the Python code (print statements)? Otherwise see here for some hints.

PS: I don't see how Gimp or the Python code could change the status of the directory. OTOH IIRC on recent Windows unknown apps are not always allowed to write files, so maybe you need to give Gimp some privileges.

I've reinstalled as Admin, and I'm able to create a script create a folder (yay!  Big Grin)

Code:
def make_dir():

 mainDir = "D:\\temp\\images"
 folder = "spoon"
 fname = os.path.join(mainDir, folder)

 # make a directory
 os.mkdir(fname)

 msg = "Make a " + folder + " directory!! " + "\n"
 gimp.message(msg)

Now the main thing is trying to work out
(a) how to get some sort of error log feedback and (b) which line/s doesn't it like.

You can just type python yourscript in a command line and python will show the most blatant errors (unbalanced quotes/parens, indentation errors, etc...). If you don't get any of these, then you can use the trick expounded in the tutorial thread above to reroute all Python output to file.

Of course, all this is a lot easier on Linux Big Grin


RE: GIMP python script from command line - ghoul fool - 12-11-2020

(12-08-2020, 11:38 PM)Ofnuts Wrote:
(12-08-2020, 09:13 AM)ghoul fool Wrote:
(12-08-2020, 07:28 AM)Ofnuts Wrote: Do you get any output from the Python code (print statements)? Otherwise see here for some hints.

PS: I don't see how Gimp or the Python code could change the status of the directory. OTOH IIRC on recent Windows unknown apps are not always allowed to write files, so maybe you need to give Gimp some privileges.

I've reinstalled as Admin, and I'm able to create a script create a folder (yay!  Big Grin)

Code:
def make_dir():

 mainDir = "D:\\temp\\images"
 folder = "spoon"
 fname = os.path.join(mainDir, folder)

 # make a directory
 os.mkdir(fname)

 msg = "Make a " + folder + " directory!! " + "\n"
 gimp.message(msg)

Now the main thing is trying to work out
(a) how to get some sort of error log feedback and (b) which line/s doesn't it like.

You can just type python yourscript in a command line and python will show the most blatant errors (unbalanced quotes/parens, indentation errors, etc...). If you don't get any of these, then you can use the trick expounded in the tutorial thread above to reroute all Python output to file.

Of course, all this is  a lot easier on Linux Big Grin


Yes, this is about the second time in a loooong time that I regret using a Windows based box. Smile

I also figured out about running a GIMP python script as "normal" python one - to check for errors. V. useful.

I also front a function to print statements as well as 
Code:
gimp.message(text)

Each time so I could at least work out how far it go.
Got there in there in the end Smile