PDF24 DocTool: wait for compression and read the exit code in a script

Home › Forums › PDF24 Toolbox › PDF24 DocTool: wait for compression and read the exit code in a script

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #63152
    aimarestebanez
    Participant

    Hi, I'm creating a script to automate the compression of pdf-s. Im having some problems with commands executing before the previous one has ended. Does PDF24 have any out variable? I have been trying with $? in Windows. But it's always true, even when the compression failed or hasn't finished yet.

    #65615
    PDF24 Support
    Moderator

    Hello,

    sorry for the late reply. The command line tool pdf24-DocTool.exe (compression with -compress) is a Windows program with a graphical interface. When such a program is started directly in PowerShell, PowerShell does not wait for it to finish. The next command starts right away, and $? only tells you that the program could be started.

    To wait, start the DocTool with Start-Process and the parameters -Wait and -PassThru. PowerShell then waits until the compression has finished, and the ExitCode property of the returned process tells you the result. In a batch file, start /wait does the same.

    Meaningful exit codes require the switch -silent, available since version 11.31.0, so please update first if necessary. In silent mode no dialogs are shown, errors are written to stderr, and the exit code is 0 on success and another value on error, e.g. 4 = no output location, 6 = the operation failed. Without -silent, the DocTool always returns 0 and reports errors in a dialog. In silent mode please give the output folder with -outputDir and set the compression with -dpi, -imageQuality and -colorModel (-useCompressionParamsDialog is not available there).

    Compressing also works online: https://tools.pdf24.org/en/compress-pdf

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.