Hi,
I'm trying to automate the execution of a command-line program in a FOR loop. My goal is to execute the first option proposed in this page to run GhostScript over all PDF files of a selected folder.
So, having captured the folder path and execution parameters in a GUI, I want the execute the following:
$cmd = 'cmd.exe /c for %a in (' & $selectedFolderPath & '\*.pdf) do gswin32c.exe -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=a4 -sOutputFile="%~na-resize.pdf" -c "<</BeginPage{0.' & $scale & ' 0.' & $scale & ' scale ' & $xoffsetpt & ' ' & $yoffsetpt & ' translate}>> setpagedevice" -f %a' Run($cmd)
Unfortunately, nothing happens. The command-line window disappears in the blink of an eye. Reading the cmd.exe reference, I suspect the problem is that some arguments of gswin32c.exe use quotation marks, and that cmd.exe is quite sensitive to that.
Any suggestion? Am I using a wrong method?
Thanks!