"Syukur, Hiroshi Ridwan" wrote:

> Hello All,
>
> Is there any way I can execute Runtime.exec() method from Servlet?
>
> I tried to insert the following code inside the doPost() method of my
> servlet, both directly or using another class but I keep getting the
> Exception error.
>
> ////////
>       Runtime r = Runtime.getRuntime();
>       Process p = null;
>         try {
>           p = r.exec(ExecutablesProgram);
>         } catch (Exception e) {
>           System.out.println("Error Executing");
>         }
> ///////
> Then, when I try to insert the code outside the doPost() method, the code
> was not executed at all...
>
> I am a novice in Servlet (and Java...), so I don't now whether Servlet is
> allowed to invoked a system call or not. If not, how can I invoke a system
> call from Web browser? (Like Perl CGI's system() function )

Overall you have not give us enough clues, but the short answer is - yes -
servlets can exec programs.
We built a system that need to use an extenal executeable to authorize logins
(SecureId cards).

You may find that a servlet that was auto-loaded from the servlets directory
can't exec a program, this depends on your
web server/ sevlet engine. If this is the case you'll have to put your servlet
in the Classpath, and forfeit the auto (re)loading.

Also look out for the fact that exec's argument string isn't passed to a shell
to execute unlike C's system() call,
so you can't put things like $HOME or whatever in the command string, hoping
that they'll be rewritten to
/home/user/bill

>
>
> Thanks in advance.
>
> Regards,
> Hiroshi
>
> Runtime.getRuntime().exec(unix_command);
>
> ___________________________________________________________________________
> 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