Forum moved here!

Home / Status feedback when called with PowerShell on Windows

Wayne

Hi All,
First off, this has helped solve a problem when trying to automate printing PDFs when called via a powershell script! - none of the ‘others’ quit correctly so caused timing issues with file locations, unwanted delays etc! So Bonus there!

One thing I would like to do is have a way to feed back any error messages from Sumatra when it is used to print a PDF eg not found printer, error due to something or another, you get the idea.

I’ve used the ‘start-process’ command within powershell to call the portable version of SumatraPDF.exe along with parameters to specify the name of the printer, the obvious file name to print and the -silent options to not let it get stuck if there is an error. I’ve also used the -wait option to get powershell to wait until the process completes (try THAT with adobe!!)

Although I’m also using powershells ‘-ErrorVariable’ for it to put messages and the like into a variable, I think this is to return errors that ‘start-process’ generates and not anything that is fed back from Sumatra.

Is this possible at all? Maybe a feature request if not?

Thanks again.
Wayne.

GitHubRulesOK

@Wayne
It’s some time since I tried to catch print failures, and don’t have the code to hand, SumatraPDF -print-to is supposed to exit gracefully (but I do also remember using -silence during testing)
“After printing, SumatraPDF exits immediately (check the error code for failure).”
it may well be that -silence zeros the errorlevel, have you tried testing from a simple cmd line / file ?

GitHubRulesOK

@Wayne
I have retested a couple of versions including current 3.12 with an old batch file under win 10 and have no reason to suspect it would behave different on XP, 7 or 8.x

With or without -silent the CLI result is simply a %errorlevel% = 0 or 1

If the printer not found or the file is missing or print is aborted then you get 1
and if not -silent you see

If the print appears to have completed on return you get 0
however if the command line is invalid and no print is requested you also get 0