Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GIMP python script from command line
#1
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.
Reply
#2
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/4443...mmand-line

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

There might be something there that helps.
Reply
#3
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"
Reply
#4
(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.
Reply
#5
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.
Reply
#6
Big Grin 
(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.
Reply
#7
(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
Reply
#8
(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
Reply


Forum Jump: