java program that starts unix script & then ends

E

Etantonio

Good morning,
I need to start a unix script from a java program, for this I used
these instructions :

Runtime rt=Runtime.getRuntime();
try {
Process proc=rt.exec("sh /root/scriptTestANDO.sh");
} catch (IOException e) {
e.printStackTrace();
}

it works ok,
but I need that the script still run also if the java program ends,
how I can arrange this ??
Thanks

Antonio
www.etantonio.it/en
 
N

Nigel Wade

Etantonio said:
Good morning,
I need to start a unix script from a java program, for this I used
these instructions :

Runtime rt=Runtime.getRuntime();
try {
Process proc=rt.exec("sh /root/scriptTestANDO.sh");
} catch (IOException e) {
e.printStackTrace();
}

it works ok,
but I need that the script still run also if the java program ends,
how I can arrange this ??
Thanks

Antonio
www.etantonio.it/en

Please don't multi-post. You're unlikely to get the answer you want. See the
other thread you started in comp.lang.java.help.

If you really, really, must post to more than one group then cross-post.
 
A

Arne Vajhøj

Lew said:
Etantonio multi-posted ...

Two, or maybe up to four, spaces per indent is enough. Sixteen-plus is
excessive.

I do not know if it makes it better, but it is tabs.

Arne
 
T

timjowers

Good morning,
I need to start a unix script from a java program, for this I used
these instructions :

Runtime rt=Runtime.getRuntime();
try {
Process proc=rt.exec("sh /root/scriptTestANDO.sh");
} catch (IOException e) {
e.printStackTrace();
}

it works ok,
but I need that the script still run also if the java program ends,
how I can arrange this ??
Thanks

Antoniowww.etantonio.it/en

Put an & at the end of your command:
sh /root/scriptTestANDO.sh &

Maybe you lack a basic understanding. When a proc starts in *nix it is
child o (descendent) of init thread (proc id 1). Do a "pstree" in
Linux. So, you want a process that keeps running. Processes only run
if their parent runs. It must be a child of another RUNNING process.
This will NEVER be the case with a JVM which ends; but, you can exec
it out as a shell script. You did. You can use the & notation in shell
to tell it to bg the process. What does this do? The process will keep
runing even after you leave your shell. Then it runs until killed.

These are not the proper way to do it. Use a cron job. crontab. You
could/can also add those from Java by calling a Linux command. Perhaps
you can get real serious and write a Java library for cron/at (at is
the Windows name of something like cron. It is also called the
schedule service but try "at" in DOS/cmd shell.) So, you make a nice
old library which uses system services and share it with the world.
Thanks! Or use Quartz or something. :-()

Best,
TimJowers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top