The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

using runtime.exec in a jsp

Posted by Doug on February 20, 2002 at 4:50 PM

CAN THIS BE DONE IN A JSP? I'VE TRIED TO IMPLEMENT IT, BUT THE CALL DOESN'T SEEM TO GO THROUGH. ANY SUGGESTIONS?

> Hi,
> I was trying to run a batch file from my program, so I did the following:
> public static void main (String []args) {
> /*
> Threadtest t = new Threadtest();
> t.start();*/
> testrun();
> }

> public static void testrun () {
> BufferedReader br = null;
> BufferedReader br2 = null;
> Process p = null;
> int status = -1;
> try {
> String osName = System.getProperty("os.name");
> if (osName.compareTo("Windows NT") == 0) {
> //String []test = "cmd.exe", "/c", "runtest.bat");
> p = Runtime.getRuntime().exec("cmd.exe /c runtest.bat ");
> }
> br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
> String s;
> while ((s = br.readLine())!= null) {
> System.out.println(s);
> }
> br2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
> while ((s = br2.readLine())!= null) {
> System.out.println(s);
> }
> br.close();
> br2.close();
> }catch (IOException ioex) {ioex.printStackTrace();}
> //return 0;
> }
> Now, this starts the dos prompt, and then the program waits on it.
> It only continues after I kill the dos prompt. Is there any way that I can start the process and then forget about it?
> I dont want to have any control after spawning off the process.
> Could anyone help me with this problem?
> Thanks
> Sasipriya






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us