0

I started my solution with what was suggested here GhostScript print to network printer in silent mode

And came up with this as a command line

gswin32c.exe -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=mswinpr2 -sOutputFile="%printer%\\printserver\testprinter" "C:\absolute\file\path.pdf"

And it works nicely, when the printer is available. When the printer is not available (or doesn't exist), it spawns a print dialog. This command is being run by a custom cron service and therefore gets stuck when the dialog opens on a non interactive user.

Is there a command line switch to tell it to send to STDERR instead and just fail the print job?

Alternatively, is there a way to get ghostscript to output the available devices and I could search for the device before printing?

Trevor
  • 101
  • 3
  • Can you ping %printer% first? By cron, do you mean the windows task scheduler? – Señor CMasMas Oct 06 '21 at 14:27
  • @SeñorCMasMas no I wrote my own task scheduler that behaves like cron but with a web interface. I tried pinging the printer but no luck, says not found. – Trevor Oct 06 '21 at 14:45
  • Try adding `-dNOPROMPT`. – harrymc Oct 06 '21 at 14:59
  • @harrymc just tried, it still gave the prompt. Is there a way for me to get a list of all devices instead? I could script it to fail before trying to print if the device isn't in the list – Trevor Oct 06 '21 at 15:01

1 Answers1

0

I was able to find a solution.

Using the command wmic printer get Name I get a list of printer names. Then if the required printer is in the list, I allow the ghostscript command to run, if not then I block it. This helps lower the chance of a lockup from the printer selection dialog popping up on an non interactive user.

Trevor
  • 101
  • 3