How can i launch a gimp command line from a python script ? - 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: How can i launch a gimp command line from a python script ? (/Thread-How-can-i-launch-a-gimp-command-line-from-a-python-script) |
How can i launch a gimp command line from a python script ? - alvaro562003 - 09-18-2017 Hello, From this stackoverflow thread https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line , i extract this command line: Code: gimp-console -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')" -b "pdb.gimp_quit(1)" It worls perfectly well. Now, i would like to run this command from a python script, usually i use subprocess.Popen....but it does not work and i get this message: "batch command experienced an execution error" How can i launch the gimp command line from a python script ? Thanks RE: How can i launch a gimp command line from a python script ? - Ofnuts - 09-18-2017 Better give some extract of your Python code that includes the Popen call as well as the exact error. I would expect something like: Code: Popen(["/path/to/gimp.exe","-idf","--batch-interpreter","python-fu-eval","-b","import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')","-b","pdb.gimp_quit(1)"])
RE: How can i launch a gimp command line from a python script ? - alvaro562003 - 09-18-2017 Hi Ofnuts, Thank you for you feedback, I take into account your remarks, here is the code genereating the error: gimpPipe = subprocess.Popen( ["C:/Program Files/GIMP 2/bin/gimp-console-2.8.exe", '-idf', '--batch-interpreter', 'python-fu-eval','-b', "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')", '-b', "pdb.gimp_quit(1)"], shell=False ) gimpPipe.wait() To better understand, i simplify the command : gimpPipe = subprocess.Popen( ["C:/Program Files/GIMP 2/bin/gimp-console-2.8.exe", '-idf', '--batch-interpreter', 'python-fu-eval','-b', "import sys;sys.path=['.']+sys.path;", '-b', "pdb.gimp_quit(1)"], shell=False ) and there is no error So, the error is coming from the adjunction of: -b', "import batch;", maybe a question of path RE: How can i launch a gimp command line from a python script ? - Ofnuts - 09-18-2017 Do you have a valid batch.py file in your current directory? The basic idea is that "import sys;sys.path=['.']+sys.path;" adds a directory to the Python path (here it's '.', so that's the current directory when the command is issued, but it could be '/path/to/the/script/directory') while 'import batch' imports batch.py from that directory, and 'batch.run()' calls the run() function in it. PS; Please take the habit to copy the error message when you report an error... I can't read it over your shoulder. RE: How can i launch a gimp command line from a python script ? - alvaro562003 - 09-19-2017 (09-18-2017, 08:19 PM)Ofnuts Wrote: Do you have a valid batch.py file in your current directory? The basic idea is that "import sys;sys.path=['.']+sys.path;" adds a directory to the Python path (here it's '.', so that's the current directory when the command is issued, but it could be '/path/to/the/script/directory') while 'import batch' imports batch.py from that directory, and 'batch.run()' calls the run() function in it. @ofnuts, Thank so much, it works: I am now able to apply a gimp filter to all files in a directory |