Redirect error and output stream using java program
I'm facing following problem:
1. I have a Java program which calls other java program.
2. I call the other java program by:
---> I run the batch file.
Process proc =Runtime.getRuntime().exec(batchFile);
---> This batch file calls the java program.
Now In my main application that is main java program I'm capturing error and output stream of DOS command
line so that it will be displayed by my swing application.
proc.getInputStream() and proc.getErrorStream().
But I'm not able to capture the error stream
If I don't capture the streams and run command window it will display error as
well as o/p on command window.
I'm not getting what is going wrong over here.
Thanks in advance.
Lee
Re: Redirect error and output stream using java program
try using redirectErrorStream(true); so that you can read it using getInputStream()
Chris
Re: Redirect error and output stream using java program
Hi,
Thanks for the reply.
I cannot do this for following two reasons:
1. I want to capture error streams and o/p streams differently as they are treated differently by my swing application.
2. It is not that I'm not able to catch the error stream completely.
The java class which I'm calling through the batch file has the main() method. If I throw some exception in that class and I catch it. It will be redirected to the Error stream.
But If it is being thrown from some other class then it cannot be captured by error stream.
Initially I thought it is due to the fact that may be log4j is redirecting it to some other place. But thats not true if I run this through command line I can view all error and o/p msg.
Lee
Re: Redirect error and output stream using java program
I'm facing following problem:
1. I have a Java program which calls other java program.
2. I call the other java program by:
---> I run the batch file.
Process proc =Runtime.getRuntime().exec(batchFile);
---> This batch file calls the java program.
Now In my main application that is main java program I'm capturing error and output stream of DOS command
line so that it will be displayed by my swing application.
proc.getInputStream() and proc.getErrorStream().
But I'm not able to capture the error stream
If I don't capture the streams and run command window it will display error as
well as o/p on command window.
I'm not getting what is going wrong over here.
Idont want to use try redirectErrorStream(true); or following two reasons:
1. I want to capture error streams and o/p streams differently as they are treated differently by my swing application.
2. It is not that I'm not able to catch the error stream completely.
The java class which I'm calling through the batch file has the main() method. If I throw some exception in that class and I catch it. It will be redirected to the Error stream.
But If it is being thrown from some other class then it cannot be captured by error stream.
Initially I thought it is due to the fact that may be log4j is redirecting it to some other place. But thats not true if I run this through command line I can view all error and o/p msg.
Lee
Re: Redirect error and output stream using java program
Hi,
This is solved. We need to read input and error stream in two different threads to avoid the blocking.
Re: Redirect error and output stream using java program
Quote:
Originally Posted by
leenabora
Hi,
This is solved. We need to read input and error stream in two different threads to avoid the blocking.
I'm glad you resolved your problem leenabora.