• Post Reply Bookmark Topic Watch Topic
  • New Topic

Starting an application from Java and not wait for the return  RSS feed

 
Stephan Wissel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compute a command line e.g. "winword.exe demo.doc" or "/usr/bin/myappp ~/somedata.dat" and want to launch it. I do not want/need to wait for the result of the external app and the external app needs to be independent from my Java app, so it continues running when my app already has terminated. I had a look at Runtime.getRuntime().exec() but that "waits" for the application and the app wouldn't survive Java application end. What do I need to do?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't wait for it. I would advise you to read: When Runtime.exec() won't
 
Stephan Wissel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:It doesn't wait for it. I would advise you to read: When Runtime.exec() won't


I did read that. And I found:

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

So I conclude:
- it is a subprocess and won't survive termination of my Java application
- it needs "handholding" for input/output streams

I would really like to send it off as independent running program.

So what should I do?
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Execute it in such a way that the input and output streams don't come to your program. (Actually there is little point in executing programs which use those things in the way you suggest, since you propose to ignore them anyway.) Winword is fine because it doesn't use stdin or stdout.

Are you're proposing to write a general-purpose application executor, or what?
 
Stephan Wissel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Execute it in such a way that the input and output streams don't come to your program.

That is exactly my question (part of it). How do I execute so the streams don't block if I ignore them.

Paul Clapham wrote:Are you're proposing to write a general-purpose application executor, or what?

Something like that. Some logic in a server provides input parameters to a signed applet (that has sufficient rights) and applications are started that a user interacts with and might or might not close them. E.g thew work on a document that was loaded, but then close that one and work on another.

In C (on Windows) it is:



I need to find the Java equivalent (or how to wrap the call to C)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!