Keith,
Your problem is that you need to define a Process object, which is the
return of the exec() method, so that you can capture the InputStream of your
command's output.
Try something like the following:
try {
p = Runtime.getRuntime().exec("mkdir ItWorked");
InputStream is = p.getInputStream();
BufferedReader bis = new BufferedReader(new InputStreamReader(is));
String line = null;
while((line = bis.readLine()) != null) {
out.println(line+"<br>");
} // end while loop
bis.close();
} catch (IOException e) {
out.println("Error executing request: "+e.getMessage());
return;
} // end catch
NOTE: This code was a cut & paste from a more complex general purpose
command runner class. Please forgive me if there are errors in the syntax.
This should give you an idea of how to proceed however.
Also, this month's news letter from the Sun Java Developer's Connection
contains an article on this topic.
----- Original Message -----
From: Keith Ball <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 22, 2000 2:40 AM
Subject: Runtime.getRuntime().exec("java comline");
> Hi,
>
> I have a problem in my Servlets. I need to execute commands from inside
my
> servlets. I can execute commands from the shell by using "java
comline"...
> and this works fine.
>
> import java.io.*;
>
> public class comline {
> public static void main(String[] arguments) {
> try {
> Runtime.getRuntime().exec("mkdir ItWorked");
> } catch(IOException ex) {
> System.err.println("IOException : " + ex.getMessage());
> }
> }
> }
>
> However the following code.......
>
> import javax.servlet.http.*;
> import javax.servlet.ServletException;
> import java.io.*;
> import java.util.*;
>
> public class test extends HttpServlet {
>
> public void doGet(HttpServletRequest request, HttpServletResponse
> response)throws IOException
>
>
> HttpSession UserSession = request.getSession(true);
> response.setContentType("text/html");
> PrintWriter out = response.getWriter();
>
> out.println("<HTML>");
> out.println("<BODY>");
> out.println("<h5>Current Date : " + new Date() + "</h5>");
>
> try {
> Runtime.getRuntime().exec("mkdir ItWorked");
> } catch(IOException ex) {
> System.err.println("IOException : " + ex.getMessage());
> }
> out.println("</body></html>");
> out.close();
> }
> }
>
> This does not work. My system setup is. SuSE 6.3 i386, apache 1.3.11
with
> jserv 1.1.
>
> Does anyone know why this command will not execute?
>
> Some possible reasons I have looked at are :
> 1. Setting the user to somebody other than nobody and then giving
ownership
> of the directory to them.
> 2. Path to mkdir not set.
>
> However none of these changes made any effect. Another intresting thing
is
> it reports no error's. However if I try and use .....
>
> Runtime.getRuntime().exec("java comline");
>
> From inside the servlet, it report the error that it can't find the file
> java. It obviously doesn't use the same path's as bash. I am stumped can
> anyone help me?
>
> Thanks,
>
> Keith
> --------------------------------------------------------------------------
-
> Keith Ball - Praktikant
> WA46 Operationelle Analysen Luftwaffe
> IABG MbH Einsteinstr. 20 85521 Ottobrunn
> Phone : 0049-89-6088-2556
> Email : [EMAIL PROTECTED] WWW site : www.iabg.de
> --------------------------------------------------------------------------
--
>
>
___________________________________________________________________________
> 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