Here is a part of code which I had used for copying a file. Modify it for
using javac. Probably you need to go to
the relevant directory first.. i.e. cmd[2] will be "cd c:\mydir" and then
use javac or use javac with option that allows you to mention path.

   // works for DOS
   String cmds[] = new String[5];
   cmds[0] = "cmd";
   cmds[1] = "/c";
   cmds[2] = "copy";
   cmds[3] = "CommandMapping.java ";
   cmds[4] = "xxxx.java ";

   File currentDir = new File("c:\\temp");
   // execute the command
   Process pro = Runtime.getRuntime().exec(cmds, null, currentDir);
   // wait until it's done executing
   pro.waitFor();
   // what did the process output from the Input pipe back to
   // this process (okay, who named this stuff)?
   InputStream out = pro.getInputStream();
   // output it (really slowly)
   int i;
   while ((i = out.read()) != -1) System.out.print((char) i);

hope this helps,
-sourabh

----- Original Message -----
From: tudor.sava <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 21, 2001 4:45 AM
Subject: Re: OT Run a system command from java.


> Ok !!!
>
> It works with "Notepad.exe"
> Can you explain me why if when I try to execute "javac Application.java"
> (Application.java is a valid java application in current directory) isn't
> work. That I need.
> Help....
> Initially a used a native interface and I used System() from C and it
works.
>
> Thx in advance. Tudor
>
>
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Thierry Boutevin
> Sent: Thursday, February 14, 2002 10:34 AM
> To: [EMAIL PROTECTED]
> Subject: Re: OT Run a system command from java.
>
>
> Yes here is an exemple
>
> RT = Runtime.getRuntime()  ;
>
>      try {
>            p = RT.exec("notepad.exe")      ;
>           } catch(IOException e) {
>           System.out.println("IOException: " + e.getMessage());
>           }
>
> Thierry
>
>
> |--------+------------------------------->
> |        |          "Dahnke, Eric"       |
> |        |          <[EMAIL PROTECTED]|
> |        |          OM>                  |
> |        |          Sent by: "A mailing  |
> |        |          list for discussion  |
> |        |          about Sun            |
> |        |          Microsystem's Java   |
> |        |          Servlet API          |
> |        |          Technology."         |
> |        |          <SERVLET-INTEREST@JAV|
> |        |          A.SUN.COM>           |
> |        |                               |
> |        |                               |
> |        |          14/02/2002 00:57     |
> |        |          Please respond to "A |
> |        |          mailing list for     |
> |        |          discussion about Sun |
> |        |          Microsystem's Java   |
> |        |          Servlet API          |
> |        |          Technology."         |
> |        |                               |
> |--------+------------------------------->
>
>
>---------------------------------------------------------------------------
> ---------------------------------|
>   |
> |
>   |       To:     [EMAIL PROTECTED]
> |
>   |       cc:
> |
>   |       Subject:     OT Run a system command from java.
> |
>
>
>---------------------------------------------------------------------------
> ---------------------------------|
>
>
>
> Perl and PHP have exec() or system() to invoke OS level executeables.
> Does
> Java have anything similar?
>
>
> Regards, Eric
>
>
___________________________________________________________________________
>
> 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
>
>
___________________________________________________________________________
> 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