• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java as a child process  RSS feed

 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was trying a sample program to run another java file from my java file using Runtime.exec(). Here's the code for the sample program




Can anyone tell me why this happens? Is there an alternative to achieving the task
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try reading the ErrorStream and InputStream of the Process instance. you should see the program output or any error in those.
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote:Try reading the ErrorStream and InputStream of the Process instance. You should see the program output or any error in those.


Thanks , it works now. But , can you tell me why we get the stream as a separate one . I thought that the child process can share the stream with the parent process, But this does not seems true in this case.

Also there's one more problem, when I apply the same thing to a swing/webapp as the parent process, then it seems the parent terminates the child process without waiting for it to complete. So, how to achieve this stuff in a swing/webapp? Do I need to pause the parent Thread explicitely?
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal Shaw wrote:can you tell me why we get the stream as a separate one


Sometimes you will need the stdout and stderr outcome of the child process, so there must be a way to capture it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!