Hi,

  I have also faced the same problem, rather than putting the command in an
String Array, put those command in an batch file(for Dos) or executable
Shell File(for Unix) and than call that file in your program like this:

  String cmd = "a.bat"; (Dos) or
  String cmd = "a.sh";  (Unix)

  Hope this helps,

  With Regards,

B.Karthikeyan.

----- Original Message -----
From: Sam <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 09, 2001 8:32 AM
Subject: Execute an external program,


>
> Hi all,
>
>     The code I try to execute an external program.
>     For my servlet program,
>     To launch a Unix script String[] cmd = {"/bin/sh", "-c", "ls >
> out.dat"};
>     Runtime.getRuntime().exec(cmd);
>     ==
>              try {
>                  String[] command = {"/bin/sh", "-c", "/bin/ls >
out.dat"};
>                  Process p = Runtime.getRuntime().exec(command);
>                  p.waitFor();
>                  System.out.println("return code: " + p.exitValue());
>              } catch (IOException e) {
>                  System.err.println("IO error: " + e);
>              } catch (InterruptedException e1) {
>                  System.err.println("Exception: " + e1.getMessage());
>              }
>     ==
>     Process p = Runtime.getRuntime().exec("/usr/local/bin/test");
is
> okay, too. (without parameter)
>     == (test is a simple c execute program)
>
>     HOWEVER, I try to change the command line to
>     String[] command = {"/usr/local/bin/test > /tmp/tmp.dat"}
>
>     It does not work!!
>     Because ">" is a shell command! It must be interpreted by /bin/sh.
>
>     So! How do I execute a external program with shell command?
>     --> String[] comand = {"/bin/sh", "-c", "/usr/local/bin/test >
> /tmp/tmp.dat"};
>
>     It still does not work...
>
>     Anybody kindly give me some hints?
>     Thanks!
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to