• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1018
  • Last Modified:

java runtime bat file run and close java program.

Hello experts!

The code snippet below runs a bat file that executes for about six hours.  I am on a windows 2003 operating system.  I would like to be able to have the user submit the job then go home.  In the morning an e-mail message tells them the job has completed, success or failure.  I have everthing working except when the user closes the window that executed the code snippet below, the backround process ends.  Is there a way in JAVA on a windows 2003 operating system to submit a background process that is not a child process.  Any code or pointers to documentation would be great.


                runtime = Runtime.getRuntime();
                String[] cmd = {"cmd",
                    "/c", "start",
                    "java -cp E:\\Winapps\\TrialBalance;E:\\Winapps\\TrialBalance\\classes;c:\\java\\javamail\\javamail-1.4ea\\mail.jar;c:\\java\\javaactivation\\jaf-1.0.2\\activation.jar Main \"false\" \"ALL\" \"" + fy +"\""};
                p = runtime.exec(cmd);
                af.writeLogEntry("Submitted process");
                af.writeLogEntry("Command -> E:\\Winapps\\TrialBalance;E:\\Winapps\\TrialBalance\\classes;c:\\java\\javamail\\javamail-1.4ea\\mail.jar;c:\\java\\javaactivation\\jaf-1.0.2\\activation.jar Main \"false\" \"ALL\" \"" + fy +"\"");

Thanks

Kevin
0
kmccusker
Asked:
kmccusker
  • 5
  • 2
  • 2
  • +4
2 Solutions
 
CEHJCommented:
AFAIK the only way to have a 'background' process that can't be shut down easily is to use a Windows service. See

http://wrapper.tanukisoftware.org/
0
 
objectsCommented:
use the job scheduler to run the application, that way it won't exit and you can also control when it starts.
0
 
WebstormCommented:
try to use javaw instead of java to avoid console window that user can close.

instead of:
                    "java -cp E:\\Winapps\\TrialBalance;E:\\Winapps\\TrialBalance\\classes;c:\\java\\javamail\\javamail-1.4ea\\mail.jar;c:\\java\\javaactivation\\jaf-1.0.2\\activation.jar Main \"false\" \"ALL\" \"" + fy +"\""};

use:
                    "javaw -cp E:\\Winapps\\TrialBalance;E:\\Winapps\\TrialBalance\\classes;c:\\java\\javamail\\javamail-1.4ea\\mail.jar;c:\\java\\javaactivation\\jaf-1.0.2\\activation.jar Main \"false\" \"ALL\" \"" + fy +"\""};
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
WebstormCommented:
You can also avoid cmd :

                String[] cmd = {"javaw","-cp",
 "E:\\Winapps\\TrialBalance;E:\\Winapps\\TrialBalance\\classes;c:\\java\\javamail\\javamail-1.4ea\\mail.jar;c:\\java\\javaactivation\\jaf-1.0.2\\activation.jar",
                 "Main","false","ALL", fy };
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You can perhaps start it as a background process if you append & at the end of the command.
0
 
CEHJCommented:
>>if you append & at the end of the command.

Only in *nix
0
 
Mayank SAssociate Director - Product EngineeringCommented:
As a matter of fact, I tried it in windows server 2003 enterprise edition and somehow it works~!
0
 
WebstormCommented:
On Windows shell (DOS), & is used to call multiple commands :   cmd1... & cmd2...
(equivalent of ; on Unix/Linux)

&& and || can be used on Windows & Unix/Linux.
but there is no other equivalent of & (Unix/Linux) in Windows than "start".
0
 
DeanHorakCommented:
Simply use the Windows START command

i.e.

START background.cmd

or

START /B background.cmd               if you don't want a window

0
 
orhanbabaCommented:
you can use start

start /B /SEPARATE commands

if you have multipler process. like dir rmdir mkdir... you  can use it like that.
start /B /SEPARATE dir
start /B /SEPARATE mkdir meeek
:)
each process start at the samte time.
0
 
WebstormCommented:
Don't repeat what have already been said !
0
 
kmccuskerAuthor Commented:
Wow!

  I just wanted to say thank you.  I split the points between webstorm and objects.  Webstorm pointed out the problems I needed to resolve with my java program.  However, objects pointed out on windows 2003 I already have a program, the scheduler, that will do the task for my user.  Why re-invent the wheel unless you want to! :)  Again, I thank you for the quick response and the great advise.

Kevin
0
 
WebstormCommented:
:-)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now