Fire a process off and have it keep running after perl script is done -


i using perl script fire off jar needs stay running. however, want perl process end. thought thread solve problems: how can fire , forget process in perl?

however, have tried both forking , using system(cmd &) techniques , in both perl script stays running.

here code fork:

if (index($all_jars, 'myjar.jar') == -1) {   unless(fork) {   }   else {     exec("java -jar myjar.jar");   } } 

here code system(cmd &): wasn't sure if meant type cmd & command or command & both systems didn't quit perl script until after jar process died.

system("cmd & java -jar myjar.jar");  or  system("java -jar myjar.jar &"); 

not sure doing wrong... or ideas give me.

i have a lot of experience in domain, , i've learned best way create background process that can outlive parent process depends on operating system.

in unix, can ask system run job in background or use fork , exec:

system("java -jar myjar.jar &");  if (fork() == 0) {     exec("java -jar myjar.jar");     die "exec shouldn't have returned"; } 

note logic (unless(fork){...}else{exec(...)}) backwards , calling exec in parent process.

in windows, best way create background process runs in separate process group system 1, ... hack:

system 1, "java -jar myjar.jar"; 

check $^o see operating system running under:

if ($^o eq 'mswin32') {     system 1, "java -jar myjar.jar"; } else {     system "java -jar myjar.jar &"; } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -