You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by hui zhang <zh...@cse.concordia.ca> on 2007/01/15 03:28:47 UTC

Runtime.getRuntime.exec() problem

Hi Everybody,

Now I am trying to launch an external application, for example, "top" 
,in my web application, and killing it by PID after a while. But when I 
execute Runtime.getRuntime.exec("top") in my JSP page or Servlet, Tomcat 
is stuck in that page and do not display anything because it can not 
stop running until that "commnad" is terminated, which means it waiting 
for the response from Runtime.getRuntime.exec("top"). It seems that it 
will run forever. Is there any solution to solve this problem? I mean 
that JSP page can execute the following code no matter if it finish the 
process is done.

BTW, I do not use System.exit() in my program. It may cause Security 
Manager problem.
Thanks and best regards,

Hui

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hui,

hui zhang wrote:
> "TOP" is only an example in this case. Actually I am running some
> program which can not stop running until terminating it by "Control +
> C". In this case, Tomcat can not run the following code if the external
> application does not stop. I need a solution to make my webapp running
> in this case. Thank you.

Please post the code for your servlet. There is no reason that spawning
another process should stall your servlet unless you are explicitly
waiting for that process to exit.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFq6Z49CaO5/Lv0PARAk6LAJ9QmM6uhmacn3bM9RF9OzV/ryGZ4gCfWK25
9IlIku8nTfZtu8ZAteYakjw=
=BHtQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by Zack Grafton <za...@gmail.com>.
hui zhang wrote:
> Zack Grafton wrote:
>> hui zhang wrote:
>>> Zack Grafton wrote:
>>>> hui zhang wrote:
>>>>> Hi Everybody,
>>>>>
>>>>> Now I am trying to launch an external application, for example, 
>>>>> "top" ,in my web application, and killing it by PID after a while. 
>>>>> But when I execute Runtime.getRuntime.exec("top") in my JSP page 
>>>>> or Servlet, Tomcat is stuck in that page and do not display 
>>>>> anything because it can not stop running until that "commnad" is 
>>>>> terminated, which means it waiting for the response from 
>>>>> Runtime.getRuntime.exec("top"). It seems that it will run forever. 
>>>>> Is there any solution to solve this problem? I mean that JSP page 
>>>>> can execute the following code no matter if it finish the process 
>>>>> is done.
>>>>>
>>>>> BTW, I do not use System.exit() in my program. It may cause 
>>>>> Security Manager problem.
>>>>> Thanks and best regards,
>>>>>
>>>>> Hui
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>
>>>>>
>>>> Hey,
>>>>
>>>> I'm new to the list and all, but you might want to try executing 
>>>> "top" in batch mode.  The command line option is -b on my gentoo 
>>>> linux box.  Also, be careful of executing commands from applets and 
>>>> such.  Another thing might be user permissions as well.  You could 
>>>> try executing the command and redirecting the output to a file and 
>>>> parsing the file instead.
>>>>
>>>> Zack Grafton
>>>>
>>>> ---------------------------------------------------------------------
>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> Hi,
>>>
>>> "TOP" is only an example in this case. Actually I am running some 
>>> program which can not stop running until terminating it by "Control 
>>> + C". In this case, Tomcat can not run the following code if the 
>>> external application does not stop. I need a solution to make my 
>>> webapp running in this case. Thank you.
>>>
>>> Regards,
>>>
>>> Hui
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>> Hui,
>>
>> You could check out the javadoc for the java.lang.Process class.  You 
>> would need to do something like:
>>
>> Process process = Runtime.getRuntime().exec("command");
>>
>> process.getInputStream();
>> process.getOutputStream();
>>
>> Just remember to wrap the streams appropriately and you should be 
>> able to read the stdin and stdout of the program.  That should allow 
>> you to send the <control>+C signal to the program.
>>
>>
>> Zack Grafton
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
> Hi,
>
> I can get the InputStream from process object. How can I send 
> Control+C to the console next? I can not send another command to 
> console until this command is terminated.
>
> BTW, what is the string format of "Control + C"?
>
> Thanks!
>
> Regards,
>
> Hui
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Hui,

Not too sure, but I found a website that says its the decimal value of 
the ascii character.  Not too sure though.  So for ctrl+c it might be 
decimal value 4.  Otherwise, I have no clue.  Which program is it that 
you're trying to run?  There might be an alternative application if 
everything else doesn't work.


Zack

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by Zack Grafton <za...@gmail.com>.
hui zhang wrote:
> Zack Grafton wrote:
>> hui zhang wrote:
>>> Zack Grafton wrote:
>>>> hui zhang wrote:
>>>>> Hi Everybody,
>>>>>
>>>>> Now I am trying to launch an external application, for example, 
>>>>> "top" ,in my web application, and killing it by PID after a while. 
>>>>> But when I execute Runtime.getRuntime.exec("top") in my JSP page 
>>>>> or Servlet, Tomcat is stuck in that page and do not display 
>>>>> anything because it can not stop running until that "commnad" is 
>>>>> terminated, which means it waiting for the response from 
>>>>> Runtime.getRuntime.exec("top"). It seems that it will run forever. 
>>>>> Is there any solution to solve this problem? I mean that JSP page 
>>>>> can execute the following code no matter if it finish the process 
>>>>> is done.
>>>>>
>>>>> BTW, I do not use System.exit() in my program. It may cause 
>>>>> Security Manager problem.
>>>>> Thanks and best regards,
>>>>>
>>>>> Hui
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>
>>>>>
>>>> Hey,
>>>>
>>>> I'm new to the list and all, but you might want to try executing 
>>>> "top" in batch mode.  The command line option is -b on my gentoo 
>>>> linux box.  Also, be careful of executing commands from applets and 
>>>> such.  Another thing might be user permissions as well.  You could 
>>>> try executing the command and redirecting the output to a file and 
>>>> parsing the file instead.
>>>>
>>>> Zack Grafton
>>>>
>>>> ---------------------------------------------------------------------
>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> Hi,
>>>
>>> "TOP" is only an example in this case. Actually I am running some 
>>> program which can not stop running until terminating it by "Control 
>>> + C". In this case, Tomcat can not run the following code if the 
>>> external application does not stop. I need a solution to make my 
>>> webapp running in this case. Thank you.
>>>
>>> Regards,
>>>
>>> Hui
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>> Hui,
>>
>> You could check out the javadoc for the java.lang.Process class.  You 
>> would need to do something like:
>>
>> Process process = Runtime.getRuntime().exec("command");
>>
>> process.getInputStream();
>> process.getOutputStream();
>>
>> Just remember to wrap the streams appropriately and you should be 
>> able to read the stdin and stdout of the program.  That should allow 
>> you to send the <control>+C signal to the program.
>>
>>
>> Zack Grafton
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
> Hi,
>
> I can get the InputStream from process object. How can I send 
> Control+C to the console next? I can not send another command to 
> console until this command is terminated.
>
> BTW, what is the string format of "Control + C"?
>
> Thanks!
>
> Regards,
>
> Hui
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Hui,

You might also want to look at the destroy method of the Process class.

Zack

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by hui zhang <zh...@cse.concordia.ca>.
Zack Grafton wrote:
> hui zhang wrote:
>> Zack Grafton wrote:
>>> hui zhang wrote:
>>>> Hi Everybody,
>>>>
>>>> Now I am trying to launch an external application, for example, 
>>>> "top" ,in my web application, and killing it by PID after a while. 
>>>> But when I execute Runtime.getRuntime.exec("top") in my JSP page or 
>>>> Servlet, Tomcat is stuck in that page and do not display anything 
>>>> because it can not stop running until that "commnad" is terminated, 
>>>> which means it waiting for the response from 
>>>> Runtime.getRuntime.exec("top"). It seems that it will run forever. 
>>>> Is there any solution to solve this problem? I mean that JSP page 
>>>> can execute the following code no matter if it finish the process 
>>>> is done.
>>>>
>>>> BTW, I do not use System.exit() in my program. It may cause 
>>>> Security Manager problem.
>>>> Thanks and best regards,
>>>>
>>>> Hui
>>>>
>>>> ---------------------------------------------------------------------
>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>> Hey,
>>>
>>> I'm new to the list and all, but you might want to try executing 
>>> "top" in batch mode.  The command line option is -b on my gentoo 
>>> linux box.  Also, be careful of executing commands from applets and 
>>> such.  Another thing might be user permissions as well.  You could 
>>> try executing the command and redirecting the output to a file and 
>>> parsing the file instead.
>>>
>>> Zack Grafton
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>> Hi,
>>
>> "TOP" is only an example in this case. Actually I am running some 
>> program which can not stop running until terminating it by "Control + 
>> C". In this case, Tomcat can not run the following code if the 
>> external application does not stop. I need a solution to make my 
>> webapp running in this case. Thank you.
>>
>> Regards,
>>
>> Hui
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> Hui,
>
> You could check out the javadoc for the java.lang.Process class.  You 
> would need to do something like:
>
> Process process = Runtime.getRuntime().exec("command");
>
> process.getInputStream();
> process.getOutputStream();
>
> Just remember to wrap the streams appropriately and you should be able 
> to read the stdin and stdout of the program.  That should allow you to 
> send the <control>+C signal to the program.
>
>
> Zack Grafton
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
Hi,

I can get the InputStream from process object. How can I send Control+C 
to the console next? I can not send another command to console until 
this command is terminated.

BTW, what is the string format of "Control + C"?

Thanks!

Regards,

Hui

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by Zack Grafton <za...@gmail.com>.
hui zhang wrote:
> Zack Grafton wrote:
>> hui zhang wrote:
>>> Hi Everybody,
>>>
>>> Now I am trying to launch an external application, for example, 
>>> "top" ,in my web application, and killing it by PID after a while. 
>>> But when I execute Runtime.getRuntime.exec("top") in my JSP page or 
>>> Servlet, Tomcat is stuck in that page and do not display anything 
>>> because it can not stop running until that "commnad" is terminated, 
>>> which means it waiting for the response from 
>>> Runtime.getRuntime.exec("top"). It seems that it will run forever. 
>>> Is there any solution to solve this problem? I mean that JSP page 
>>> can execute the following code no matter if it finish the process is 
>>> done.
>>>
>>> BTW, I do not use System.exit() in my program. It may cause Security 
>>> Manager problem.
>>> Thanks and best regards,
>>>
>>> Hui
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>> Hey,
>>
>> I'm new to the list and all, but you might want to try executing 
>> "top" in batch mode.  The command line option is -b on my gentoo 
>> linux box.  Also, be careful of executing commands from applets and 
>> such.  Another thing might be user permissions as well.  You could 
>> try executing the command and redirecting the output to a file and 
>> parsing the file instead.
>>
>> Zack Grafton
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
> Hi,
>
> "TOP" is only an example in this case. Actually I am running some 
> program which can not stop running until terminating it by "Control + 
> C". In this case, Tomcat can not run the following code if the 
> external application does not stop. I need a solution to make my 
> webapp running in this case. Thank you.
>
> Regards,
>
> Hui
>
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
Hui,

You could check out the javadoc for the java.lang.Process class.  You 
would need to do something like:

Process process = Runtime.getRuntime().exec("command");

process.getInputStream();
process.getOutputStream();

Just remember to wrap the streams appropriately and you should be able 
to read the stdin and stdout of the program.  That should allow you to 
send the <control>+C signal to the program.


Zack Grafton


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by Jeff Waugh <ja...@ic.net>.
"hui zhang said"
> 
> Zack Grafton wrote:
> > hui zhang wrote:
> >> Hi Everybody,
> >>
> >> Now I am trying to launch an external application, for example, "top" 
> >> ,in my web application, and killing it by PID after a while. But when 
> >> I execute Runtime.getRuntime.exec("top") in my JSP page or Servlet, 
> >> Tomcat is stuck in that page and do not display anything because it 
> >> can not stop running until that "commnad" is terminated, which means 
> >> it waiting for the response from Runtime.getRuntime.exec("top"). It 
> >> seems that it will run forever. Is there any solution to solve this 
> >> problem? I mean that JSP page can execute the following code no 
> >> matter if it finish the process is done.
> >>
> >> BTW, I do not use System.exit() in my program. It may cause Security 
> >> Manager problem.
> >> Thanks and best regards,
> >>
> >> Hui
> >>
> > Hey,
> >
> > I'm new to the list and all, but you might want to try executing "top" 
> > in batch mode.  The command line option is -b on my gentoo linux box.  
> > Also, be careful of executing commands from applets and such.  Another 
> > thing might be user permissions as well.  You could try executing the 
> > command and redirecting the output to a file and parsing the file 
> > instead.
> >
> > Zack Grafton

Try 'top -n10 to do 10 interations and then exit. Top will run forever
otherwise. Limiting it with -n will allow it to exit.

HTH,
-Jeff


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by hui zhang <zh...@cse.concordia.ca>.
Zack Grafton wrote:
> hui zhang wrote:
>> Hi Everybody,
>>
>> Now I am trying to launch an external application, for example, "top" 
>> ,in my web application, and killing it by PID after a while. But when 
>> I execute Runtime.getRuntime.exec("top") in my JSP page or Servlet, 
>> Tomcat is stuck in that page and do not display anything because it 
>> can not stop running until that "commnad" is terminated, which means 
>> it waiting for the response from Runtime.getRuntime.exec("top"). It 
>> seems that it will run forever. Is there any solution to solve this 
>> problem? I mean that JSP page can execute the following code no 
>> matter if it finish the process is done.
>>
>> BTW, I do not use System.exit() in my program. It may cause Security 
>> Manager problem.
>> Thanks and best regards,
>>
>> Hui
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> Hey,
>
> I'm new to the list and all, but you might want to try executing "top" 
> in batch mode.  The command line option is -b on my gentoo linux box.  
> Also, be careful of executing commands from applets and such.  Another 
> thing might be user permissions as well.  You could try executing the 
> command and redirecting the output to a file and parsing the file 
> instead.
>
> Zack Grafton
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
Hi,

"TOP" is only an example in this case. Actually I am running some 
program which can not stop running until terminating it by "Control + 
C". In this case, Tomcat can not run the following code if the external 
application does not stop. I need a solution to make my webapp running 
in this case. Thank you.

Regards,

Hui




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Runtime.getRuntime.exec() problem

Posted by Zack Grafton <za...@gmail.com>.
hui zhang wrote:
> Hi Everybody,
>
> Now I am trying to launch an external application, for example, "top" 
> ,in my web application, and killing it by PID after a while. But when 
> I execute Runtime.getRuntime.exec("top") in my JSP page or Servlet, 
> Tomcat is stuck in that page and do not display anything because it 
> can not stop running until that "commnad" is terminated, which means 
> it waiting for the response from Runtime.getRuntime.exec("top"). It 
> seems that it will run forever. Is there any solution to solve this 
> problem? I mean that JSP page can execute the following code no matter 
> if it finish the process is done.
>
> BTW, I do not use System.exit() in my program. It may cause Security 
> Manager problem.
> Thanks and best regards,
>
> Hui
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Hey,

I'm new to the list and all, but you might want to try executing "top" 
in batch mode.  The command line option is -b on my gentoo linux box.  
Also, be careful of executing commands from applets and such.  Another 
thing might be user permissions as well.  You could try executing the 
command and redirecting the output to a file and parsing the file instead.

Zack Grafton

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org