Forum How do I...?

prince engine standard input/output

mrossi
Hi,

since I need more control on the execution of Prince, I decided to keep the Java wrapper aside and to start the engine by means of java.lang.Process.exec().

To use standard input and standard output, the command line looks like
<path-to-prince-engine> --input=html --baseurl=file:///C:/.../t1.html -v --log=C:\\...\\prince.log - -o -

I then write on the stream returned by Process.getOutputStream() and expect to be able to read the PDF on the stream returned by Process.getInputStream(). But reading from that stream blocks seemingly forever. The prince log says:

Mon Jul 30 18:23:38 2012: ---- begin
Mon Jul 30 18:23:38 2012: Loading document...
Mon Jul 30 18:23:38 2012: loading HTML input: -
Mon Jul 30 18:23:44 2012: loading style sheet: C:\...\t1.css
Mon Jul 30 18:23:44 2012: Converting document...
Mon Jul 30 18:23:44 2012: used font: Arial, Bold
Mon Jul 30 18:23:44 2012: used font: Arial, Regular
Mon Jul 30 18:23:44 2012: used font: Arial, Italic
Mon Jul 30 18:23:44 2012: internal error: error writing to buffer
Mon Jul 30 18:23:44 2012: ---- end

If I change
-o -
to something like
-o C:\\...\\t1.pdf
and avoid reading the stream, then everything works.

What's wrong?
mrossi
I got it.

It seems that one not only needs to flush the output stream but to close it too, before being able to read from the input stream.

So please consider this case to be solved and sorry for not having investigated further before submitting the issue.
mikeday
You may want to check the source code for the Java wrapper, which demonstrates how to handle these issues.