• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

killing main process and allowing spawned process to continue

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say my main program is contained in main.jar. What I want to do is start a program such as an executable or a batch file and be able to close main.jar while the other program is running. I've included a basic example of what I'm trying to do:



However, when I run this the program waits for notepad to be closed. What I would want in this basic example is for the java program to end and notepad be left open for it to be used. Any help would be greatly appreciated.

-Thanks
Jordan
 
Marshal
Posts: 25144
64
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code will cause your application to terminate:
 
Jordan Thistle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:This code will cause your application to terminate:


When I add that after the "Runtime.exec" it doesn't exit my app. It waits for the notepad window to close. I have also tried creating a new thread before opening notepad and it doesn't help either. The second thread finishes but the java program continues to run until the notepad window is closed.



The result of runnign the code is:


The program then continues to run until the notepad window is closed. After that the java program exits without printing the "stop" line, which is to be expected.
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This surprised me -- it's certainly not the expected behavior -- so I ran your program on my Windows XP machine. I did not see what you described: after printing

exiting here
Program Terminated

I immediately got back to the C:\ prompt, while Notepad kept running. What makes you think your program is still running?
 
Jordan Thistle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:This surprised me -- it's certainly not the expected behavior -- so I ran your program on my Windows XP machine. I did not see what you described: after printing

exiting here
Program Terminated

I immediately got back to the C:\ prompt, while Notepad kept running. What makes you think your program is still running?



I figured out the problem. I was running from an IDE (NetBeans) and it was trying to hang onto the process. I compiled it and run just the executable jar file and it worked fine. Thanks for your help.

-Jordan
 
Crusading Chameleon likes the size of this ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!