This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java as a child process  RSS feed

 
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
 
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?
 
Rancher
Posts: 1017
6
  • 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.
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!