0

I am creating java process using ProcessBuilder for ghostscript to convert pdf into tiff as below

process = new ProcessBuilder("D:\\ghost-script\\gs\\gs9.02\\bin\\gswin64.exe","-q",  "-dNOPAUSE", "-dBATCH", "-dMaxStripSize=8192", "-sDEVICE=tiffg4", "-r300x300", "-dDITHERPPI=200", "-sOutputFile=D:\\ghost-script\\example\\output.tif", "D:\\ghost-script\\example\\input2.pdf", "-c", "quit").start();

Now I have two problems.

  1. This process open console popup which I don't need as it has to run on server. What parameter I can set to disable that console popup.
  2. Input file can of any be of any size. How can I know when the process has completed so that I can destroy it. I don't want Thread.sleep(time-to_sleep). Because for different size of input file it is different and if I take upper limit, it will hamper performance for lower size files badly. So what can I do to destroy the process as soon as it get completed?

Any help is much appreciated.

user207421
  • 305,947
  • 44
  • 307
  • 483
Vishal Singh
  • 624
  • 1
  • 5
  • 16
  • 1
    `Process#waitFor` might be a good start for the second question, but you need to be sure you're reading the process's output/error streams to ensure that it doesn't stall/chock. As to the first question, I'm not sure you can, but you might be able to use `start` or `cmd` to run the window minimised – MadProgrammer Feb 26 '16 at 09:49
  • I was also thinking for the same Process#waitFor but afrading if process get chocked. @MadProgrammer , can you please share some code snippet for the same and recovery from chocked process immediately. – Vishal Singh Feb 26 '16 at 10:00
  • Some processes don't like it when there output stream get's full, so you need to read it. As to knowing when you a individual process might have "chocked" despite your best efforts otherwise is dependent on the individual process, for example, you could read from the `InputStream` of the process and if you've not read anything for a given period of time, try and `destory` the process – MadProgrammer Feb 26 '16 at 10:04

1 Answers1

2

For your first question, the window comes from the executable you launch, you may want to use

gswin64c.exe

See this topic : Ghostscript suppress output windows when called by command line

For your second question, use waitFor() on the Process object.

process.waitFor();
Community
  • 1
  • 1
Arnaud
  • 17,229
  • 3
  • 31
  • 44