tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Einfeldt" <ralph.einfe...@uptime-isc.de>
Subject RE: getRuntime().exec(...) root command problem
Date Fri, 16 Jan 2004 09:25:02 GMT
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@eprocess.fr]
> 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@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message