Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

RE: getRuntime().exec(...) root command problem

Ralph Einfeldt

2004-01-16


It's not clear to me if you get an error or if you just get
no result. So I can give just general hints:

- Use the complete path to ifconfig
It should cause an exeption if you omit the pat and the
command is not found.

- The user that runs tomcat must have the right to call ifconfig
It should cause an exeption if he hasn't.

- You have to read in loop:

       InputStream out=new BufferedInputStream(p.getInputStream());
       String mLine;
       while ((mLine = out.readLine()) != null) {
          ...
       }

- You have to wait until the command is ready after the read.

   p.waitFor();


> -----Original Message-----
> From: Philippe Valle [mailto:pvalle@(protected)]
> Sent: Friday, January 16, 2004 10:01 AM
> To: Tomcat Users List
> Subject: getRuntime().exec(...) root command problem
>

> but for root command like 'ifconfig' i have nothing

>   try
>   {
>     Process p=Runtime.getRuntime().exec("/bin/sh");
>     OutputStream in=p.getOutputStream();
>     in.write(cmd.getBytes());
>     in.flush();
>     InputStream out=new BufferedInputStream(p.getInputStream());
>     byte[] b=new byte[1024];
>     int   n=out.read(b);
>     for(i=0;i<n;i++) System.out.print((char)b[i]);
>
>   }
>   catch(Exception ex) {
>   }

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)



©2008 junlu.com - Jax Systems, LLC, U.S.A.