Exec an .exe file

I have written a program that executes an .exe file using the
Runtime.exec() command and all works fine standalone with the .exe
file located in the root of my classpath.
My problem comes when I want to deploy it using WebStart, I dont know where to place the .exe where it can be found.
Ideally I dont want to install it on the client and was wondering
if it is possible to find its location programatically say in the
cache.
TIA

This is quite simple actually once you know the trick. Should probably be put into a faq....
Create a native method e.g. getNativePath and implement it to return the path of where it is located on disk. Bundle your executable and the native dll into a jar that is added in the nativelib section of the jnlp file
On windows the code may look something like the following.
* Class:     Native
* Method:    getNativePath
* Signature: ()Ljava/lang/String;
JNIEXPORT jstring JNICALL Java_Native_getNativePath(JNIEnv* env, jobject obj)
   char buf[_MAX_PATH];
#ifdef _DEBUG
   HMODULE  hmodule=GetModuleHandle("theNameOfTheDebugDll");
#else
   HMODULE  hmodule=GetModuleHandle("theNameOfTheReleaseDll");
#endif
   GetModuleFileName(hmodule, buf, _MAX_PATH);
   return (*env)->NewStringUTF(env, buf);
}Now call the executable with Runtime.exec() by prepending the path returned by the native call to getNativePath.
\Magnus

Similar Messages

  • EXEC and EXE files

    I have found some exec and exe files in with my photos in my finder.  I beleive these are old windows filesthat wre transferred over when I switched to Mac and would like to delete them but don't want to cause any issues if these files are usable and needed on my MacBook Pro.  Thanks for your help.

    You are welcome.
    Allan

  • How to control (the input and output) EXE file after I call it using exec?

    Hi,
    I knew that I can use runtime.exec() to call one EXE file, and this works. But this EXE has two characteristics:
    1. After this exe starts, it asks user to input number such as 1 or 2 onto computer screen, then press return. Then the exe will start the calculation.
    2. after it starts calculation, it prints 3 columns of numbers onto the screen.
    My two questions are:
    1. How to use java to input the number such as 1 or 2 automatically? this EXE can not work like this in DOS command line:
    C:> file.exe parameter
    The parameter is the number such as 1 or 2 that I wanna input.
    2. how to redirect the 3 columns of numbers from computer screen to txt file?
    My colleague can solve these two questions using Mathematica. So I know that definitely there is at least one solution for it. I just can not do it using Java. This wierd exe file bothered me a lot and I really wish that I can get help from someone in java community.
    Thank you!
    Tony

    When you call Runtime.exec, you get a Process object. (I presume something similar happens when you use ProcessBuilder.) Process has methods with names getOutput, getInput, and getError. These correspond to the standard input, standard output, and standard error streams of the spawned process.
    You can read and write to the process on the streams corresponding to input and output that the process writes to the console.
    [add]
    In fact, you should be grabbing and reading the output/error streams anyway, because of the points raised by the Traps article. Google "Java Runtime exec traps" and you'll probably get a link to this JavaWorld article, which describes common Runtime.exec problems and how to solve them.
    Edited by: paulcw on Jun 15, 2010 4:09 PM

  • Referring remote machines exe file path in exec method

    Can i refer remote server machine's exe file path in RunTime class's exec method?

    It's not so easy to cause a program to run on another machine. In fact virus writers consider that a challenge.
    If you want to run a program on another machine, you need that machine's permission, in the form of a server that accepts requests to run programs. An FTP server can be configured to do that, and there are other servers that can do it too. Ask the administrator of the other machine about setting one up.

  • Exec exe file in jar

    Hi,
    Is there a way to execute an exe file that is inside the jar with the main class?
    Right now, I am copying the file to a folder, and executing it.
    Thanks

    Would be a great security risk...
    Not possible.

  • I can download firefox, but when I try to run it, windows 7 asks me to select a program type to run the *.exe file

    I am running windows 7 with IE 10. I want to switch to Firefox as my browser. I am able to download the Firefox Setup 22 0 exe, but when I try to open or run it, windows prompts me to "choose the program you want to use to open this file". This happens with both the Firefox Setup Stub 22 0 exe (274kb) and the Firefox Setup 22 0 exec (21,239Kb). I can't find any program on Windows to run this exe. Same thing happens when I try to run the troubleshooter exe.

    Hello annsboland
    Do you have also problem with others exe files ?
    try to create a new user account in Windows 7 and check it again
    see if the next articles in the links helps to create the new account:
    http://www.bleepingcomputer.com/tutorials/create-new-user-account-in-windows-vista-7/
    http://www.pcadvisor.co.uk/how-to/windows/3326039/how-add-new-user-account-in-windows-7/
    thank you

  • How to execute a .exe file in java(Jsp) without using a process ???

    Hi All ,
    How to execute a .exe file in Jsp without using a process ??? ...
    Is it Possiable ????

    itsdhanasaraa wrote:
    But as this a web application ... By using Runtime i'm getting some probs ..
    Let me guess, you want your web application to run a program on the client and to your surprise that's not working?
    Ain't gonna happen.
    its taking more time to execute .... that's y is there any other option to execute .exe file other than Runtime.getRuntime().exec("filename");Write proper English and you may be taken more seriously.
    1) it's not "taking more time to execute", whatever that's supposed to mean.
    2) there's no other way to execute something. Not that you should every use even that way anyway
    3) whenever you start thinking of executing external programs from Java, start thinking of not using Java in the first place.

  • Through Java code I want to execute a exe file which is in aJar file

    I am having some classes and an exe file in a directory. I have made them in to a Jar file. In a class file which is in that jar file i want to execute a Exe file which is also resides in that jar file. Is it possible to exexute that EXE file?
    For Example....
    1. Im having a directory named CLIENT.
    2. In that directory I have 10 clss files and an EXE file.
    3. These class files and EXE files are ziped in to a Jar file.
    4. I have to give the Jar file to my client.
    5. He can put that Jar file where ever he installed my product may be C driver or D drive like that
    Now the problem is...
    I want to execute the Exe File from one of the class where both the exe file and class file resides in the Jar file
    This is my requirment
    Can anyone Help to me to solve this problem?
    Thanks in Advancd
    Ibram Shah.A.M
    ([email protected])

    The answer is to extract the EXE into a temp directory, execute it, and delete it when you're done. For example:
    //This is the path *inside* the JAR file!
    InputStream in = getClass().getResourceAsStream("/resources/myprog.exe");
    OutputStream out = new FileOutputStream("myprog.exe");
    File file = new File("myprog.exe");
    int data;
    while((data = in.read()) >= 0) out.write(data);
    in.close();
    out.close();
    //Execute the EXE here using java.lang.Runtime.exec()
    if(file.exists()) file.delete();
    ...

  • Process Class:How to give and get data from an exe file continuously???

    hi,,,
    I am trying to run an executable file from my program to give it input and read its output....
    And i am having problems...
    The exe file takes one input and appends to it "1235" (ITS A TEST CASE).
    When it is only for a single input , the program rums perfectly.. but when it is within a loop it does not
    Pls help
    Here is the code for that EXE file. (its in C)
    #include<stdio.h>
    int main()
    char a[10];
    int i;
    int k=1235;
    while(1){
    scanf("%s",a);
    if(a[0]=='s')
    break;
    printf("%s%d\n",a,k);
    }Note that when i remove the loop here, my code is able to get and give it data.
    My JAVA program::
    import java.io.*;
    public class Main {
      public static void main(String[] args) throws IOException {
            try {
          String line;
          Process p = Runtime.getRuntime().exec
            ("C:\\users\\Untitled3.exe");
           BufferedWriter   out=new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
              out.write("dfgsfs\n");
              time= java.lang.System.nanoTime();
              out.flush();
          BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(input.readLine());
          input.close();
        catch (Exception err) {
          err.printStackTrace();
    }PLS HELP

    I see a problem in your C code. You're not flushing stdout after you printf and that usually means java is not seeing whats your C program is printing.
    removing the loop probably works because stdout is being flushed right before exit.
    I used a perl script to test your stuff and found that flushing made the trick
    #!/usr/bin/perl
    open(OUTFILE,">>./output.txt");
    $| = 1;
    while (<STDIN>) {
        if (m/.*error.*/) {
            print STDERR  $_;
        } else {
            print STDOUT  $_;
        print OUTFILE $_;
        if (m/exit/) {
            last;
    close(OUTFILE);
    exit;notice "$| =1;" that autoflushes in perl (just in case you were wondering where my flush call went)
    Enjoy!

  • 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.

  • 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

  • Webserver in seperate exe file??

    Hi Guys
    So - I'm developing a piece of software that aqquires data from a USB board - this has been working well for years, everybody is happy..
    Now I want to publish the results to users via the NI web server.. Using the web publishing tool I have created a html doc from a sub VI within  the main application with the front panel I wish to publish, and that displays various values updated every 5 seconds..(the monitor function, NOT remote control).. I quickly realized that when a number of browsers are looking at the VI my main application starts to hang - have not been able to fully understand why, but I guess the NI core waits for each request to be shipped.. not really a problem since I'm not doing a VI to be published on facebook with +1.000.000 viewers - but since it potentially stalls the entire application, I risk that my measurement is disrupted, which is a no go, since the measurement may be in the field somewhere, and not next to a guy at an office desk.. Thus - I moved the call to the sub-VI into an external call using a static VI reference and the front panel open / Run methods and the "wait untill Done" flag set to false.
    This too is working very well and inside the development system I can now "sabotage" the application with multiple hits on the "refresh" button of a browser without stalling the application.. now problems arise - part because I do not have a full working knowledge of how the runtime engine operates, i guess - but... when I build this program into an exe, I can again stall the program by hitting the "refresh" button fast.... I assume that the runtime engine treats everything called from within the exe file in one thread?? 
    Questions:
    Is there a way (in a labVIEW .EXE file) to call a VI from another VI that totally separates them from each other so that if 'mainprogram' calls 'webserver', and 'webserver' hangs for some reason, this does not cause 'mainprogram' to equally hang? Could I for instance change the execution system of the VI with all 'webserver' related contant in the "execution" options?
    If not - I guess building two exe files 'mainprogram' & 'webserver' and then launch 'webserver' using system exec from 'mainprogram' will prove a solution.
    however - this means that now passing of data is no longer possible - in 2010 using lv8.6, what is the best means to move data back and forth between two seperate exe files? Ideally I would send a cluster of refnum's of the indicators from 'mainprogram' then read the values of these in 'webserver' and update the display here - but is the reference addresses from one exe, anything worth in the other exe (two seperate address spaces etc)?
    Should I learn to use datasockets - or would a TCP approach be the best? We are not talking massive amounts of data - in the area of 15 value and string controls + 2 graphs with less than 1000 points. Remember that this should only be done locally between two exe files on the same computer, to I would prefer to keep this as simple as possible - something like a pipe used in Unix code. 
    Last but not least - is there a way to run 'webserver' as some sort of service, so that the user will avoid having a window open he does not need, or a minimized 'webserver' window in the taskbar?
    many questions - and yes I know that I can read all about datasockets and TCP in the forum halls - and I'm doing it, but I would prefer to not waste too many days brushing up on new stuff not needed because my plan is wack from the start..
    Thank you for your help. 

    this is my question regarding the .exe files.
    what if i whant to make my project available for every one, not only for those that already have jre instaled, and someone that doesn't know or doesn't want to install jre want's to benefit from it????
    what do u have to answer to that??
    a serious answer please..!!

  • How to display a .exe file in java applets by avoiding the file downloadbox

    Hi sir,
    I know that in order to display a any file(or)program in java applets you need to use showDocument().Where you cannot use exec() in java applets.
    My problem is that when i use showDocument() to display .exe file.It is showing a file download dialog box.If we click & open only it is opening that .exe file.Here i want to open the .exe file without showing that file download dialog box in java applets.
    Since,i am undergoing a project which involves it,it is quite urgent.pls.do provide the exact code in java applet without showing that file download dialog box.If it can't be done pls. do provide any other possibilities in order to be displayed on the browser.Thank U.
    Regards,
    m.ananthu

    Hi!
    I think you it's better to write a server socket program
    in server and open a socket connection to server socket then
    send exe file content via connection.
    (I guess you know applets only have permission to open socket connection to their code base)
    Bye!

  • Exec(iexplore.exe) works in IE6 but not IE7

    The following statement invoked from an applet works fine with IE6 but not with IE7:
    Process process = Runtime runtime.exec(iexplore.exe slicprint.html))
    With IE6 the browser (iexplore.exe) is launched and the slicprint.html file is rendered (appears on screen).
    With IE7 the program just "hangs", i.e.the browser does not get launched (nothing displays on the screen).

    Welcome to the Sun forums. But..
    >
    The following statement invoked from an applet works fine with IE6 but not with IE7:>
    Process process = Runtime runtime.exec(iexplore.exe slicprint.html))..please refrain from posting such rot. That statement could not compile, let alone run.
    Instead, it is better to [copy/paste errors and code snippets,|http://pscode.org/javafaq.html#exact] or better still, post an SSCCE of failing code.
    Hmm.. and just so we are all clear. Why exactly are you not calling [AppletContext.showDocument(URL)|http://java.sun.com/javase/6/docs/api/java/applet/AppletContext.html#showDocument(java.net.URL)] to achieve this functionality that has been available to sandboxed applets since Java 1.1 and works, most of the time, cross-browser and cross-platform?

  • Exe file not producing the output files

    Could anyone please help me with my exe file. I have an exe file "exeFile" which takes more than one file as input from the source "c:/files" and produces some files as output into the destination "c:/files". Both my source and destination is same. My code given below is neither showing any error nor outputting any files. My code is:
    private static void compilingFiles() throws IOException
         String FirstParam = "C:/files";      
         String SecondParam = "C:/files";
         Process proc =Runtime.getRuntime().exec("cmd /c start /MIN C:/files/exeFile " + FirstParam, (String[])null, new File(SecondParam));
    }

    After going through The reference, I modified my code as under. My first exe file "tex" is doing the necessary as before, that is producing the output files to the destination, but the second exe file "fi2t1" is not producing the necessary output.
    My output after running this file is:
    <ERROR>
    </ERROR>
    Process exitValue1: 0
    <ERROR>
    </ERROR>
    Process exitValue2: 0
    <ERROR>
    </ERROR>
    Process exitValue1: 0
    <ERROR>
    </ERROR>
    Process exitValue2: 0
    <ERROR>
    </ERROR>
    Process exitValue1: 0
    <ERROR>
    </ERROR>
    Process exitValue2: 0
    So as per The reference, I think my code is right - "So, MediocreExecJavac works and produces an exit value of 2. Normally, an exit value of 0 indicates success; any nonzero value indicates an error.".
    So please tell me where am I wrong. My code is:
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.*;
    public class FontDriverCompile
         public FontDriverCompile()
         void compileFile(File newFile, String renameSub, File outputfile) throws IOException
              String FirstParam = "C:\\Temp\\sample\\font-driver.tex";  
              String FirstParam2 = "C:\\Temp\\sample";
              String SecondParam = "C:\\Temp\\sample";  
              try
                   Process proc1 =Runtime.getRuntime().exec("cmd /c start /MIN C:/Temp/sample/tex " + FirstParam, (String[])null, new File(SecondParam));
                   InputStream stderr = proc1.getErrorStream();
                   InputStreamReader isr = new InputStreamReader(stderr);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   System.out.println("<ERROR>");
                   while ( (line = br.readLine()) != null)
                        System.out.println(line);
                   System.out.println("</ERROR>");
                   int exitVal1 = proc1.waitFor();
                   System.out.println("Process exitValue11: " + exitVal1);
              catch (Throwable t)
                   System.out.println("t.printStackTrace()_1");
                   t.printStackTrace();
              try
                   Process proc2 =Runtime.getRuntime().exec("cmd /c start /MIN C:/Temp/sample/fi2t1 " + FirstParam2, (String[])null, new File(SecondParam));
                   InputStream stderr = proc2.getErrorStream();
                   InputStreamReader isr = new InputStreamReader(stderr);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   System.out.println("<ERROR>");
                   while( (line = br.readLine()) != null)
                        System.out.println(line);
                   System.out.println("</ERROR>");
                   int exitVal2 = proc2.waitFor();
                   System.out.println("Process exitValue2: " + exitVal2);
              catch (Throwable t)
                   System.out.println("t.printStackTrace()_2");
                   t.printStackTrace();
    }Message was edited by:
    sony_tj

Maybe you are looking for

  • I opened my Macbook pro and now it won't start

    So I started to have issues with my MacBook Pro not recognizing the hard drive. I opened it up and started to see how dirty the inside was so I took the logic board and battery and cleaned them up. When I put eveything back together, now the machine

  • How To Use A .dll Object in Java Servlet/JSP

    I need the Solution, Is there any API's Available to do so. Ofcourse The .dll is a Microsoft Visual Basic Product.

  • Fcp 3 crashes

    I'm trying to simply create text and drag that clip onto the timeline. once i drop it in the timeline, fcp 3 "unexpectedly quits" and i have to re-start. I'm on quicktime 6.5.2, os 10.3.8, powerbook g4 1.67 ghz 768 mb ram. any suggestions?

  • Retriving archived material doc in MB51

    Hi All, I have archived few material documents, I am able to retrive them using the T.code MB51, here there are 3 check boxes at the bottom of the screen. 1. Data base 2. short documents 3. Reread short docs in Archive. 1.can any one let me know from

  • How do I get "#" round dates in an "Insert into " query

    I am trying to use the "Insert Into" type "CFQUERY" and insert a date into a field.This date has been input by the user on a web form using the syntax "<input type="text" name="DateInTheatres"...> The query is <CFQuery datasource="blah"> Insert into