How do I run an exe file from a java program?

I need to run an exe program from within a java program.
what do I need to do this?
thanks

See java.lang.Runtime.exec()

Similar Messages

  • How do I call another exe file from a Java program?

    Hi,
    I am doing a simple IDE (text editor/interpreter) for a simple programming language we are developing. It will be submitted as our project for this semester. I created an exe file (in C) which will be used as the interpreter. How do I call the interpreter from my IDE? The interpreter should run when the user clicks a button (i.e. the "Run" button). I've tried the Java Runtime class but it doesn't work. Anyone who knows how to do it?
    Thanks!

    I first tried to do a simple program that calls system commands such as dir, cd <dir>, etc.
    I do not have the exact code right now but as far as I can remember, here's what I wrote:
    class Sample{
        public static void main(String args[]) throws IOException{
           BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           String command;
           while ((command = in.readLine()).equalsIgnoreCase("exit") == false){
              try{
                Runtime.getRuntime().exec(command);
              }catch(Exception e){
                 System.err.println("Error: " + e);
          System.exit(0);
    }

  • How to run an exe file in a java program

    Hi,
    Can somebody tell me how to run an exe file in a java program.
    Thank you!

    Yes, java.lang.Runtime.exec().
    Read this carefully before you do:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Don't write a line of code before you're reviewed and understood the article completely. - MOD

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • How to invoke the .bat(batch file ) from the java program

    i want to run some commands when i run one java program.
    I wrote those dos commands on the batch file and i want to include the bat file in the java program so that i can execute the bat file when i run the java program.
    tell me the way that i can run my bat file inside the java program.

    i tried this :
    a .bat file named test.bat, with this code : copy test.bat test2.bat
    a java class, Test.class, in the same directory
    public class Test {
         public static void main(String[] args) {
              try {           
                   Runtime rt = Runtime.getRuntime();
                   Process proc = rt.exec("cmd /c test.bat");
                   proc.waitFor();
                   int exitVal = proc.exitValue();
                   System.out.println("Process exitValue: " + exitVal);
              catch (Throwable t) {
                   t.printStackTrace();
    }

  • Running an exe file from java

    Hi , can anyone tell me how to run an exe file from my java program. the exe is in the same directory as my java files . When i click on a button i want to put something in the actionPerformed() method which will launch the exe file - prog.exe
    Hope someone can help me.
    Thanks Jim

    Hi !
    Look at the RunTime class...

  • How to run exe file from inside java

    I wan to run an exe file from inside java code. How can I do it?
    Thanks

    Hi Oakam
    This is very simple. Just go through the given code below
    in place of FILEANDPATHNAME just give the exe's path and name
    Note :- adding ".exe " is not necessary
    public class exep
    public static void main(String args[])
    Runtime r = Runtime.getRuntime();
    Process p = null;
    try{
    p = r.exec("FILEANDPATHNAME");
    catch(Exception e)
    Give ur feedback
    Thanx
    Ottran

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • How to run a cygwin.bat from a java program?

    Can you please let me know how to run a cygwin.bat file from a java program and to give commands through java program. I have a program to run .exe files, but when I do the same for the cygwin.bat it doesnt work. In task mgr a BASH and a cmd.exe is running. Please help me on this & bit urgent. Thanks in advance!

    Can you please let me know how to run a cygwin.bat
    file from a java program and to give commands through
    java program. I have a program to run .exe files, but
    when I do the same for the cygwin.bat it doesnt work.Of course not. .bat files are no native executables. You need to open a shell first, like "cmd /c cygwin.bat ..."
    & bit urgent. Thanks in advance!If I had read this earlier I wouldn't have replied. Why exactly is your time worth more than anybody else's?

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How to open an MS-Word-File from a Java-Applikation ?

    Hi,
    i want to open an MS-Word-File from a Java-Applikation.
    Something like this:
    File myFile = new File("myFile.doc");
    myFile.open(); //unfortunately this methode doesn't exist
    Thanks for response

    In my opinion you have to use the Runtime.exec(String) method. I do not know the program name for msword.
    You can open a file in notepad by invoking the method Runtime.getRuntime().exec("notepad c:/xyz/abc.txt");
    Runtime runTime = Runtime.getRuntime();
    runTime.exec("programName" + " " + file);
    Of course the computer on which the program runs must have the application!
    Hope this helps!

  • Creating a file from a Java Program

    Hi all,
    if I want to store a byte array to a file somewhere in the middle of my program... is it possible to create the file inside my Java program, i.e. the file will be created during the execution of my program, and then write this byte array into it? The name of the file to be created is predefined by me, and not thru user input.
    If so, does anyone have a sample source code to show me? or redirect me to somewhere ?
    Thanks in advance!
    Joe

    You can take a look at the File, FileOutputStream, FileInputStream classes. A simple one will be like:
    byte[] ar = {12,13,14};
    File file = new File("wee.dat");
    if (!file.exists())
    try
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(ar);
    }catch (IOException io){}
    else
    ...

  • Unable to run an exe file from a Servlet

    I am not able to run a Servlet that calls an exe file using the following code. trial.exe is was built from a C program and it is simply a program that creates a text file with some content. I am using Tomcat 6.0 and JDK 1.5 on a Windows XP.
    {color:#000080}try
    Runtime rt=Runtime.getRuntime();
    String[] command = {"C://Tomcat 6.0//webapps//ROOT//WEB-INF//classes//trial.exe"};
    {color}
    {color:#000080}
    Process p = Runtime.getRuntime().exec(command);
    p.waitFor();
    catch(Throwable t)
    // System.out.print(t.getMessage());
    }{color}
    Before running the code on Tomcat I've compiled the code above in a simple java programe and it executed without any problem.
    Then I compiled the code within a servlet. No luck. Then I treid the following options:
    Executed the Tomcat service under the context of a user by specifying a user(Log On option) for the Tomcat service.
    Then with Local System Account, selecting &ldquo;Allow service to interact with desktop&rdquo;.
    this time also, no luck. Can somebody help me on this please ?
    BJJ

    For clarity I am rewriting the last sentences here:
    Then I compiled the above code within a servlet successfully and invoked the servlet from a browser with and without the following settings of Tomcat 6.0.
    1. Executed the Tomcat service under the context of a user by specifying a user (Log On option) for the Tomcat service.
    2. Then with Local System Account, selecting �Allow service to interact with desktop�.
    I was not succeeded with any of the methods mentioned above.

  • Running an exe file from jsp

    Hi,
    Do you know a way to run the "startup.exe" Tomcat file from jsp?
    I have to start and stop a server remotely.
    Max

    public Process pFiglio;
    Runtime rt = Runtime.getRuntime();
    pFiglio = rt.exec("c:\\Tomcat\\startup.exe ");
    then you can have
    pFiglio.waitFor();
    iEsito = pFiglio.exitValue();
    pFiglio.destroy();
    Look at specification:
    http://java.sun.com/j2se/1.5.0/docs/api/
    Look class "Runtime" and "Process".
    Ema

  • How to create a exe file from a Java application

    hi,
    i have developed an application in java,now i want to distribute it to my client, for this i need to build a .exe file out of this application.
    i already have a jar file ,now can i convert a jar file to a exe file.
    im trying this out with JSmooth project but im getting it right, so can anyone help me .
    thanks,
    vishal j

    if u use dos to run your app like
    "java myapp"
    u can create a shortcut link
    in target wright java remove the path
    just leave the file name without the extension,
    like this Target: "java myapp"
    when u click on appy u'll c that java gets its full path, thats fine
    that works 4 me, ofcourse ur client needs to have JRE or JDK.

Maybe you are looking for

  • Can't get two IMacs to connect with Migration Asst. Help please.

    Trying to get my older and tired IMac connected to a newer one via Migration Assistant.  They don't see each other and they both are on my home network.  Help please

  • Invoking a Button on a PDF form, from an external browser/frame

    Using LiveCycle Forms, I have created a PDFForm (from an XDP template) with a 'submit' Button, in one frame. Does anyone know how to I can click a button from a different HTML frame, which will invoke the 'submit' button on the PDFForm? If you have J

  • How do I get the difference of time and/or date using JavaScript?

    Hi All, I have four user text entry values (Date and Time) which require a difference to be performed on them.  The results would be put into a fifth text box named "Burn_Time". The entries are Start_Date, Start_Time, Stop_Date, and Stop_Time. How do

  • Infotype 583 update

    hi all, ihve used hr_infoyte_operation for updating 583 but im not abl e to pass Q0583-CNVCD (convayence type ) to FM bcoz its structure is different from infotype 583 sturcture.how to pass that value.i tried to use hr_maintiain_masterdata.but its no

  • How to set background ChoiceBox item color to ChoiceBox with css?

    How to set background ChoiceBox item color to ChoiceBox with css? I need to change items list backgound color. I tried with following code, but it doesnt helps: .choice-box .context-menu {   -fx-backgound-color: red; .choice-box .menu-item{   -fx-bac