Juan Carlos wrote:

> Hi friends,
>
> ¿How to execute an linux command, to obtain any
> information, using Java?  (ex:  the CAT command).
> I have Red Hat version 5.3, and jdk1.1.5.

Juan,

You need to use one of the 'exec' methods available on the Runtime class and
then redirect output from the instantiated Process object.
This simple example should get you started. See JDK docs for details,

<quote>
import java.io.*;

public class test
{
 static void main(String[] args)
 {
  int rc;
  char[] buf = new char[1024];

  Runtime rt = Runtime.getRuntime();
  try {
   Process pr = rt.exec("cat /etc/hosts");

   BufferedReader in = new BufferedReader(new
InputStreamReader(pr.getInputStream()));
   do {
    rc = in.read(buf);
    if (rc > 0)
     System.out.print(buf);
   } while (rc != -1);
  }
  catch (java.io.IOException ex)
  {
   System.err.println(ex.getMessage());
   ex.printStackTrace();
  }
 }
}
</quote>

--
David Marshall                  email:  [EMAIL PROTECTED]
President                       phone:  1-941-596-2480
VM Systems, Inc.                fax:    1-941-596-2483




----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to