Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run batch command line in Fu console beginning with 'gimp'
#1
If I run the following code in Fu console

Code:
(gimp -i -b '(batch-crop-to-content "D:\Test\*.png")')

or

Code:
(gimp -b '(batch-crop-to-content "D:\Test\*.png")')

so I receive the following error message:

Code:
Error: syntax error: illegal token 1

 
Please help to understand this error.
 
I would like to run the command line via a batch script, but I receive only
"batch command executed successfully" and cant' see more details.
 
How to force detailed output for gimp-2.10.exe console without "echo off" to be able to see for possible errors in the chain of procedures?
In the batch script I have explicitly set "echo on" but this not help here, because gimp-2.10.exe is started as a separate process.
 
Thanks
Reply
#2
maybe try to start GIMP from terminal* with --verbose
Code:
gimp --verbose
then run your script, maybe you will have more details in the terminal

in all case
Code:
man gimp
is your friend in the terminal to know what you can pass

   

EDIT
* I just saw you're on Microsoft's Windows, commands above are for Linux/MacOS, you might need to adapt those command for your OS
Reply
#3
Thanks.

In the meantime I have figured it out: With the parameter --verbose I get the detailed output on the Gimp console - this works fine, however absolutely no errors are listed.

But attention:
This parameter can be placed only before the parameter -b! Otherwise it will proceed the script with vebose output but leads on the end to error:

Code:
Error: eval: unbound variable: --verbose

It seems to be a bug.
And abbreviations like -v or --v are not supported! Or more precisely -v does something completely different and indeed shows the versions of the Gimp modules without to process the rest of the code on the same command line.

However, I haven't found out yet how the command line is to be inserted directly in the Fu console, so that I can at least try it out there to see if it so finally starts up.

On the other hand via the GUI menu the both commands - "crop to content" (early "auto crop, before Gimp v.2.10) and "zealous crop" - works fine and the same pictures are processed without any problems.
 
A very strange thing.

Enclosed is a summary of everything - perhaps anyone will notice the error:

batch-crop-to-content.scm:
Code:
(define (batch-crop-to-content pattern)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
    (let* ((filename (car filelist))
        (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
        (drawable (car (gimp-image-get-active-layer image))))
    (plug-in-autocrop RUN-NONINTERACTIVE image drawable)
    (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
    (gimp-image-delete image))
    (set! filelist (cdr filelist)))))

or analogously for batch zealous crop:
batch-zealous-crop.scm
Code:
(define (batch-zealous-crop pattern)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
    (let* ((filename (car filelist))
        (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
        (drawable (car (gimp-image-get-active-layer image))))
    (plug-in-zealouscrop RUN-NONINTERACTIVE image drawable)
    (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
    (gimp-image-delete image))
    (set! filelist (cdr filelist)))))

And in batch script it is like:
Code:
@echo on
echo.
 
PushD %~dp0
 
set "gimp=%ProgramFiles%\GIMP 2\bin\gimp-2.10.exe"
 
"%gimp%" -i --verbose -b '(batch-crop-to-content "*.png")' -b '(gimp-quit 0)'
 
timeout /t 3 >nul

(resp. for zealous crop with adjusted line: '(batch-zealous-crop "*.png")' instead of '(batch-crop-to-content "*.png")')
 
And again: via batch script everything is executed without errors, but the *.png files (that are of course in the same directory of the batch scripts) are not processed but the same pictures are processed with the both commands via the GUI.
Reply
#4
gimp -i -b '(batch-crop-to-content "D:\Test\*.png") is a shell/terminal command that calls Gimp, not a script-fu instruction. You cannot use it in the script-fu console.

Gimp batch is executed by calling Gimp from a terminal (gimp -i -b, and giving it a script-fu/python-fu script to execute ('(batch-crop-to-content "D:\Test\*.png")').

To make things even more confusing the syntax of shell commands (in particular, relative to single quotes and double quotes) is different between Windows and Unix (Linux and OSX) so make sure you follow examples for the proper OS.
Reply
#5
As ofnuts states syntax between linux and Windows.

This works in linux batch-autocrop.scm in Gimp script folder
Code:
(define (batch-autocrop pattern)


 (let* ((filelist (cadr (file-glob pattern 1))))
   (while (not (null? filelist))
          (let* ((filename (car filelist))
                 (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
                 (drawable (car (gimp-image-get-active-layer image))))
                 

            (plug-in-autocrop RUN-NONINTERACTIVE image drawable)
           
            (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
            (gimp-image-delete image))
          (set! filelist (cdr filelist)))))

and in a terminal
Code:
 gimp  -i -b '(batch-autocrop "*.png" )' -b '(gimp-quit 0)'

Basically what is given in the Gimp docs.

Tried all ways in a Win10 VM with no success, forward slashes / double (escape) slashes / various quotes). Script runs, nothing happens.

How many files do you need to process ? The Gimp BIMP batch plugin works (autocrop is 'other' Gimp procedure)
Reply
#6
(09-24-2022, 12:35 PM)Ofnuts Wrote: gimp -i -b '(batch-crop-to-content "D:\Test\*.png") is a shell/terminal command that calls Gimp, not a script-fu instruction. You cannot use it in the script-fu console.
Clear statement!

(09-24-2022, 12:35 PM)Ofnuts Wrote: Gimp batch is executed by calling Gimp from a terminal (gimp -i -b, and giving it a script-fu/python-fu script to execute ('(batch-crop-to-content "D:\Test\*.png")').

If you mean script-fu instruction would be only this part, so it does not work like that either directly in fu console:
Code:
(batch-crop-to-content "D:\Test\*.png")

I receive:

Code:
> (batch-crop-to-content "D:\Test\*.png")
()


(09-24-2022, 12:35 PM)Ofnuts Wrote: To make things even more confusing the syntax of shell commands (in particular, relative to single quotes and double quotes) is different between Windows and Unix (Linux and OSX) so make sure you follow examples for the proper OS.

Yes, and here you are absolutely right!

The solution is with the following syntax (in Windows Batch scripts each double quote of the inside pair must be escaped and depending on this usually succeeds with the character "\", so that this part can be passed as one argument correctly and not fragmented in many wrong arguments):
Code:
gimp -i -b "(batch-crop-to-content \"*.png\")" -b "(gimp-quit 0)"

and finally it works !
Thanks

Conclusion:
I already realize that as a Windows (and not Ubuntu … Linux) user I will experience a lot of stumbling traps here.
I wonder now why it is "as batch script" with wrong syntax everywhere in many posts/blogs, and I just blindly relied on it being correct in any case, however, from now on I will pay more attention.
Reply
#7
(09-24-2022, 09:07 PM)Gimpnik Wrote:
(09-24-2022, 12:35 PM)Ofnuts Wrote: gimp -i -b '(batch-crop-to-content "D:\Test\*.png") is a shell/terminal command that calls Gimp, not a script-fu instruction. You cannot use it in the script-fu console.
Clear statement!

(09-24-2022, 12:35 PM)Ofnuts Wrote: Gimp batch is executed by calling Gimp from a terminal (gimp -i -b, and giving it a script-fu/python-fu script to execute ('(batch-crop-to-content "D:\Test\*.png")').

If you mean script-fu instruction would be only this part, so it does not work like that either directly in fu console:
Code:
(batch-crop-to-content "D:\Test\*.png")

I receive:

Code:
> (batch-crop-to-content "D:\Test\*.png")
()


(09-24-2022, 12:35 PM)Ofnuts Wrote: To make things even more confusing the syntax of shell commands (in particular, relative to single quotes and double quotes) is different between Windows and Unix (Linux and OSX) so make sure you follow examples for the proper OS.

Yes, and here you are absolutely right!

The solution is with the following syntax (in Windows Batch scripts each double quote of the inside pair must be escaped and depending on this usually succeeds with the character "\", so that this part can be passed as one argument correctly and not fragmented in many wrong arguments):
Code:
gimp -i -b "(batch-crop-to-content \"*.png\")" -b "(gimp-quit 0)"

and finally it works !
Thanks

Conclusion:
I already realize that as a Windows (and not Ubuntu … Linux) user I will experience a lot of stumbling traps here.
I wonder now why it is "as batch script" with wrong syntax everywhere in many posts/blogs, and I just blindly relied on it being correct in any case, however, from now on I will pay more attention.

Well if you want to learn a bit of Python there are working examples out there.
Reply
#8
Thanks
Reply


Forum Jump: