Author Message

Posted: Tue Mar 09, 2010 10:40 am   Post subject: Capturing console verbose output in realtime

Hi,

When I use iSpringSDK.exe at the command line with the -v option, it progressively print out its status. E.g.:

Code:
C:\Program Files\iSpring\SDK>iSpringSDK.exe s -v "c:\temp\bob.ppt" c:\temp\alice.swf
Starting conversion
Collecting data
Slide 1 of 17
Slide 2 of 17
Slide 3 of 17
Slide 4 of 17
Slide 5 of 17
Slide 6 of 17
Slide 7 of 17
Slide 8 of 17
Slide 9 of 17
Slide 10 of 17
Slide 11 of 17
Slide 12 of 17
Slide 13 of 17
Slide 14 of 17
Slide 15 of 17
Slide 16 of 17
Slide 17 of 17
Processing data
Slide 1 of 17
[4 shapes]....
Slide 2 of 17
[7 shapes].......
Slide 3 of 17
[4 shapes]....
Slide 4 of 17
[8 shapes]........
Slide 5 of 17
[7 shapes].......
Slide 6 of 17
[7 shapes].......
Slide 7 of 17
[32 shapes]................................
Slide 8 of 17
[7 shapes].......
Slide 9 of 17
[7 shapes].......
Slide 10 of 17
[41 shapes].........................................
Slide 11 of 17
[7 shapes].......
Slide 12 of 17
[7 shapes].......
Slide 13 of 17
[7 shapes].......
Slide 14 of 17
[7 shapes].......
Slide 15 of 17
[27 shapes]...........................
Slide 16 of 17
[25 shapes].........................
Slide 17 of 17
[7 shapes].......
Writing SWF
Finished!

C:\Program Files (x86)\iSpring\SDK>

But when I try to capture (and process) the output, it blocks up until everything is written. This happens in my Java code with ProcessBuilder, and even at the command line redirecting output to a file. E.g.:

Code:
C:\Program Files\iSpring\SDK>iSpringSDK.exe s -v "c:\temp\bob.ppt" c:\temp\alice.swf > c:\output.txt


How can I capture the output of iSpringSDK as it happens?

tia,

Stu


Profile profile test

Posted: Tue Mar 09, 2010 11:56 am   Post subject: Re: Capturing console verbose output in realtime

Quote:
How can I capture the output of iSpringSDK as it happens?

This question is out of iSpring SDK functionality scope. The java.lang.Process class returned by ProcessBuilder.start() method does not allow capturing output of the child process.
If you are going to invoke iSpringSDK.exe from Java please consider using other ways to execute external application and capture its output.

BTW. iSpring SDK can be accessible from Java language using Java-COM wrapper. See the following sample illustrating event handling during conversion:
"C:\Program Files\iSpring\SDK 5\samples\server\java\sdk\samples\event_handling"


Profile profile test WWW www ICQ ICQ

Posted: Tue Mar 09, 2010 1:04 pm   Post subject: Re: Capturing console verbose output in realtime

Hi,

Thank you for the quick reply.

I respectfully disagree with your statement "The java.lang.Process class returned by ProcessBuilder.start() method does not allow capturing output of the child process." for multiple reasons.

Why?

  • My Java code does get the iSpringSDK.exe output. The problem is it that it comes all at once, and only when the process is finished.
  • java.lang.Process has two methods for getting the standard output and standard error of a process, .getOutputStream() and .getErrorStream. (The two can be merged if desired.)

    I (and many other Java developers) have code in production that reads a long-lived process' output streams as it is generated. A great example is FFmpeg.


  • iSpringSDK.exe behaves differently than other long lived processes with periodic output to standard out. An example you can try out quickly to demonstrate the problem:

    a) At the command line, run tracert 157.166.224.26. You sill see output at the console similar to iSpringSDK.exe in that there is periodic output. (As expected.)

    b) At the command line, run tracert 157.166.224.26 > c:\temp\trace.txt and watch the output file grow slowly as traceroute dumps output. You can even open the file at any moment and see how far along it is. (As I would expect iSpringSDK to behave.)

There must be some way to get writing output in a manner that parent process can interpret on the fly.


As for the Java/COM bridging, it is not my favorite idea. Firstly, I am having enough problems getting my iSpringSDK project into a production state--adding more complexity is going to be time consuming. (It still is not running as a service, despite your help in other threads.) Secondly, my application already has an external process standard out stream reading framework--moving to a Java/COM bridge approach means this project is not 'almost done' but rather 'just getting started'.

Kind regards,

Stu


Profile profile test

Posted: Tue Mar 09, 2010 1:49 pm   Post subject: Re: Capturing console verbose output in realtime

Quote:
My Java code does get the iSpringSDK.exe output. The problem is it that it comes all at once, and only when the process is finished.


Standard output in C++ is buffered by default. The buffer size is about 4 kilobytes. The buffer is flushed when the application finishes.
That is why your application is not receiving events untill the buffer is full.

Data written to stdout are not buffered when standard output is connected with a console.

We updated command line application - in one of the nearest builds the output will be flushed after each event.

However we do not recommend to rely upon the format of standard output. We do not guarantee that it won't be changed in future without any notification.

P.S. Could you please give us a sample of code you are using to get data from standard output of the process. As far as I know the OutputStream class provides methods only to write data but not to fetch them.


Profile profile test WWW www ICQ ICQ

Posted: Tue Mar 09, 2010 2:14 pm   Post subject: Re: Capturing console verbose output in realtime

OK, here is a code snippet:

Code:
pb.redirectErrorStream(true); //ProcessBuilder pb; 
//this merges stdout and stderr into a single stream

proc = pb.start();            //Process proc;

//ISpringSdkOutputStreamReader reader; 
//this is my own class that extends thread.  it is used to read the output stream from the process
reader = new ISpringSdkOutputStreamReader(this, proc.getInputStream());   

reader.start(); //starts the reader thread

int exitCode = proc.waitFor(); //waits until child proc exits


The key here is the counter intuitively named proc.getInputStream(). From the JavaDoc:
Quote:
Gets the input stream of the subprocess. The stream obtains data piped from the standard output stream of the process represented by this Process object.

So, the iSpringSDK.exe's output goes to the InputStream object, which is read from by my thread implementation ISpringSdkOutputStreamReader. The ISpringSdkOutputStreamReader instance has a simple 1-byte-at-a-time loops pulling data from the stream until it ends.

I understand and accept that the text output of iSpringSDK.exe may change over time. It's a risk I've lived with the other process my application shells out to, and we are comfortable with it.

Thank you for taking my comments seriously.

Stu


Profile profile test

Posted: Tue Mar 09, 2010 3:39 pm   Post subject: Re: Capturing console verbose output in realtime

Quote:
The key here is the counter intuitively named proc.getInputStream().

Oh, thanks.
I was always skipping this method since I thought it was used to provide child process with input data not to read its output


Profile profile test WWW www ICQ ICQ

Posted: Thu Mar 11, 2010 8:42 am   Post subject: Re: Capturing console verbose output in realtime

Quote:
We updated command line application - in one of the nearest builds the output will be flushed after each event.

Can you tell me when this will be available for downloading? My project is holding on this, and I'd like to finish it off.


Profile profile test

Posted: Thu Mar 11, 2010 10:04 am   Post subject: Re: Capturing console verbose output in realtime

I assume the build will be available for downloading in 5-6 business days. You may check the build number on a product download page (it will be higher than 5.0.0.2836)


Profile profile test WWW www ICQ ICQ

Posted: Wed Mar 17, 2010 1:02 pm   Post subject: Re: Capturing console verbose output in realtime

Hi again,

I've downloaded 5.0.0.2842 which is up now, and I'm still seeing the buffering, both with my Java and with redirecting the output to a file. :(

Stu


Profile profile test

Posted: Wed Mar 17, 2010 2:22 pm   Post subject: Re: Capturing console verbose output in realtime

Please try the following build
http://www.ispringsolutions.com/downloa ... 0_2844.msi

I can confirm that version 2842 do not have this update


Profile profile test WWW www ICQ ICQ

Posted: Thu Mar 18, 2010 1:56 pm   Post subject: Re: Capturing console verbose output in realtime

Thanks, but I'll have to try in two weeks. (Going on holiday in a few hours!)

Stu


Profile profile test
Display posts from previous:  Sort by  

  


Who is online
Who is online In total there are 4 users online :: 2 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 108 on Thu Nov 21, 2013 3:41 pm

Registered users: Bing [Bot], Google [Bot]