• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

killing main process and allowing spawned process to continue

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code will cause your application to terminate:
 
Jordan Thistle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic