9

This is my scenario:

I'm converting PDF files to PNG images calling Ghostscript by C#. This is the argument string I use:

-dNOPAUSE -dBATCH -dFirstPage=1 -q -r300   -sDEVICE=png256 -sOutputFile=...

But, in this way, when I call Ghostscript it shows a window where (before I've added -q) there were output messages.

I've tried adding -dNODISPLAY after -r300. But in this way Ghostscript doesn't work and doesn't create images.

Question: In which way can I suppress the output window?

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
SamDroid
  • 601
  • 1
  • 10
  • 28

2 Answers2

20

If you want to run Win32/Win64 Ghostscript on the commandline without having it popping up a separate window (to display its <stdout> and <stderr> messages and allow you for <stdin> input typing), then use these binaries (depending on your version of your locally installed Ghostscript):

  • gswin32c.exe (note the added c for command/console)
  • gswin64c.exe (note the added c for command/console)

Do not use gswin32.exe or gswin64.exe! These are the versions which bring along their own popup windows...

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • thank you, I was using gswin32.exe instead of gswin32c.exe. For others that have same problem, see also the nld answer at this question to hide console: http://stackoverflow.com/questions/836427/how-to-run-a-c-sharp-console-application-with-the-console-hidden – SamDroid Feb 05 '15 at 10:02
  • 1
    Can you post an example usage of how it is being called in c# ? gswin32.exe with parameters it works but when I switch gswin32.exe to gswin32c.exe at process.WaitForExit(); line it gets into infinite loops – user3079364 Apr 16 '18 at 19:32
  • I am still seeing a console window popup when using the c version... – A X Oct 24 '20 at 19:06
  • I'm seeing a console window as well. It just no longer pops up in it's own "ghostscript" console window – fudge Jul 25 '23 at 18:51
0

There are two potential windows that can pop up when you're running gs:

  • On Windows, you might get a terminal window to popup. ⇐ This isn't specific to GhostScript.
  • On all systems, you might get a render window to popup.

In case the window that you want to suppress is the render window, for example, because you want to use PostScript as a programming language, you might want to change the device to nullpage using the -sDEVICE=nullpage option:

File hello.ps

(%stdout)(w)file (Hello, world!\n) writestring

Command to run this file, without a window popping up using the nullpage with -sDEVICE=nullpage, and also suppressing GhostScript's banner message with -q:

gs -q -sDEVICE=nullpage -- hello.ps
Christian Hujer
  • 17,035
  • 5
  • 40
  • 47