1

I am trying to redirect printer's .PS file with RedMon to my Java code.

RedMon port config:

Redirect to program: C:\Program Files\Java\jre1.8.0_111\bin\java.exe

Arguments: -jar c:\dist\JavaApplication5.jar --stdin

and the Java code:

public class JavaAplication5 {

public static void main(String[] args) throws FileNotFoundException {
    BasicConfigurator.configure();                          //log4j
    System.setProperty("jna.library.path", "C:\\dist\\");   //fix path to gsdll

     FileInputStream file = new FileInputStream(args[0]);
     Ghostscript gs = Ghostscript.getInstance(); 
     String[] gsArgs = new String[10];
    gsArgs[0] = "-ps2pdf";
    gsArgs[1] = "-dNOPAUSE";
    gsArgs[2] = "-dBATCH";
    gsArgs[3] = "-dSAFER";
    gsArgs[4] = "-sDEVICE=pdfwrite";
    gsArgs[5] = "-sOutputFile=output.pdf";
    gsArgs[6] = "-c";
    gsArgs[7] = ".setpdfwrite";
    gsArgs[8] = "-f";
    gsArgs[9] =  String.format(" %s ", file) ;        

    try { 
        gs.initialize(gsArgs);
        gs.exit(); 
    } catch (GhostscriptException e) {
        JOptionPane.showMessageDialog(null, "ERROR: " + e.getMessage());
    }
}
}

How can I get this to work?

UserF40
  • 3,533
  • 2
  • 23
  • 34
remux
  • 13
  • 6

1 Answers1

0

So if I read this correctly, you have set up RedMon to send the data sent to the port to your Java application.

You then system call Ghostscript (using the ps2pdf script)and tell it to read from stdin.

But the Ghostscript stdin is not your Java program's stdin, unless I'm mis-understanding some aspect of Java.

I would expect that when you fork a Ghostscript instance that application gets its own stdin, which is not the same as the stdin associated with your Java program.

Your best bet would be to write the input to your Java program to a file and when its complete, execute Ghostscript on the file.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • But what should I expect from redmon; a File, a Path, a ByteArray... I don't know how to handle this -output from redmon - input for my Java - to have it in a file? – remux Oct 27 '16 at 19:58
  • As far as I recall, RedMon sends its output to the stdin of the application it has been directed to use. So your Java application will get a stream of bytes on stdin. I have no idea how you handle that in Java. – KenS Oct 28 '16 at 07:02