how to execute a .exe file useing a java program

  • ramana
  • Born
  • Born
  • ramana
  • Posts: 1

Post 3+ Months Ago

i need to execute an any .exe file useing java program.like in jdk we have java,javac...like that



this is the code that i wrote :




import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;


public class Test3 {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {

Process pp=run.exec("d:\\jdk1.3\\bin\\javac");
BufferedReader in =new BufferedReader(new InputStreamReader(pp.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}



when i try 2 run this code:

here i am getting this sort of error:





---------- java ----------
java.io.IOException: CreateProcess: d:\jdk1.3\bin\javac error=3
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:551)
at java.lang.Runtime.exec(Runtime.java:418)
at java.lang.Runtime.exec(Runtime.java:361)
at java.lang.Runtime.exec(Runtime.java:325)
at Test3.main(Test3.java:19)
CreateProcess: d:\jdk1.3\bin\javac error=3
Normal Termination
Output completed (0 sec consumed).


please help me in this issue...thanks in advance
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • twiztit_momma
  • Proficient
  • Proficient
  • User avatar
  • Posts: 346
  • Loc: SanLeon Tx

Post 3+ Months Ago

Readme for Java 2 Source Code, Javadocs, and Binaries


http://spamid.servebeer.com:8081/source/readme.jsp
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I was able to get the code working with some minor changes I made based on some examples that I found on this site. I'm not sure why you're getting a IOException.

This was the code that I used with the path modified for my machine:

Code: [ Select ]
import java.io.*;

public class Test3 {
    public static void main(String[] args) {
        Runtime run = Runtime.getRuntime();
        try {
        
            Process pp=run.exec("c:\\jdk1.3\\bin\\javac");
            BufferedReader in =new BufferedReader(new InputStreamReader(pp.getErrorStream()));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            int exitVal = pp.waitFor();
            System.out.println("Process exitValue: " + exitVal);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }
}
  1. import java.io.*;
  2. public class Test3 {
  3.     public static void main(String[] args) {
  4.         Runtime run = Runtime.getRuntime();
  5.         try {
  6.         
  7.             Process pp=run.exec("c:\\jdk1.3\\bin\\javac");
  8.             BufferedReader in =new BufferedReader(new InputStreamReader(pp.getErrorStream()));
  9.             String line;
  10.             while ((line = in.readLine()) != null) {
  11.                 System.out.println(line);
  12.             }
  13.             int exitVal = pp.waitFor();
  14.             System.out.println("Process exitValue: " + exitVal);
  15.         } catch (Exception e) {
  16.             e.printStackTrace();
  17.             System.out.println(e.getMessage());
  18.         }
  19.     }
  20. }


The output was the same as if I typed it from the command line with the exit value variable added:

Code: [ Select ]
Usage: javac <options> <source files>
where possible options include:
 -g            Generate all debugging info
 -g:none          Generate no debugging info
 -g:{lines,vars,source}  Generate only some debugging info
 -O            Optimize; may hinder debugging or enlarge class file

 -nowarn          Generate no warnings
 -verbose         Output messages about what the compiler is doing
 -deprecation       Output source locations where deprecated APIs are us
ed
 -classpath <path>     Specify where to find user class files
 -sourcepath <path>    Specify where to find input source files
 -bootclasspath <path>   Override location of bootstrap class files
 -extdirs <dirs>      Override location of installed extensions
 -d <directory>      Specify where to place generated class files
 -encoding <encoding>   Specify character encoding used by source files
 -target <release>     Generate class files for specific VM version

Process exitValue: 2
  1. Usage: javac <options> <source files>
  2. where possible options include:
  3.  -g            Generate all debugging info
  4.  -g:none          Generate no debugging info
  5.  -g:{lines,vars,source}  Generate only some debugging info
  6.  -O            Optimize; may hinder debugging or enlarge class file
  7.  -nowarn          Generate no warnings
  8.  -verbose         Output messages about what the compiler is doing
  9.  -deprecation       Output source locations where deprecated APIs are us
  10. ed
  11.  -classpath <path>     Specify where to find user class files
  12.  -sourcepath <path>    Specify where to find input source files
  13.  -bootclasspath <path>   Override location of bootstrap class files
  14.  -extdirs <dirs>      Override location of installed extensions
  15.  -d <directory>      Specify where to place generated class files
  16.  -encoding <encoding>   Specify character encoding used by source files
  17.  -target <release>     Generate class files for specific VM version
  18. Process exitValue: 2

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 79 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.