Executing a Windows EXE within Java Enviornment

I would like to know how can i call a windows exe from within a Java Application.
For instance i would like to call the windows calculator or the paint program that has the exe file calc.exe
How would i get this calculator from within Java
I am working on the follwoing code but it dosent work.
Runtime r = Runtime.getRuntime ();
Process p = r.exec ("cmd /c calc.exe");
PLZ HELP
Regards,
SHAIRANI

ThankX a million dear nuno ....
Ur help n post certainly helped me a great deal and made my concepts even clearer ...!!!
thankyou so very much once again.
i came across another solution at this forum that works really KEWL ...!
the solution that i came across is ......
import java.lang.*;
import java.io.*;
public class runWinProg {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
//String[] callAndArgs = { "Notepad.exe","D:\\TEMP\\Test.txt" };
String[] callAndArgs = { "calc.exe"};//,"D:\\TEMP\\Test.txt" };
          try {
          Process child = rt.exec(callAndArgs);
          child.waitFor();
          System.out.println("Process exit code is: " + child.exitValue());
          catch(IOException e) {
          System.err.println(
          "IOException starting process!");
          catch(InterruptedException e) {
          System.err.println(
          "Interrupted waiting for process!");
} //end of main method
} //end of class
Regards,
SHAIRANI

Similar Messages

  • Problem executing .bat file from within Java class

    I'm stumped: I have no problem executing a .bat file that sets classpaths and executes a Java jar, but when I try to execute other executables first and then the .jar, my application hangs and since the DOS box doesn't come up over my GUI, I can't see what's going on.
    This works:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\omni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat 'omni.bat'
    set JAVA_HOME=c:\j2sdk1.4.2_04\bin
    %JAVA_HOME%\java -jar C:\CS47AUXS\OMNILOADJAR\OmniLoad.jar
    This doesn't work:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\jobomni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat file 'jobomni.bat'
    SET NETX_HOME=C:\CS47AUXS
    SET COBOL_HOME=C:\CS47AUXS\OFFLINE
    CD %NETX_HOME%
    CALL SET-NETX.CMD
    CD %COBOL_HOME%
    SSBPPC10 JOBOMNI X
    SET JH=C:\J2SDK1.4.2_04\BIN
    SET OMNI_HOME=C:\CS47AUXS\OMNILOADJAR
    CD %OMNI_HOME%
    %JH%\java -jar omniload.jar
    Can anyone shed some light here? Even when I execute the application from the command line the new DOS box doesn't become visible nor can I see any errors. If I could just get that visibility, I could probably figure out what is going wrong.

    Same problem with me as well.... Badly looking for a solution...
    I predict the following:
    - If your batch file has pretty less number of dos/shell commands then it gets executed fine with exec() and proc.waitFor();
    - If you increase the number of dos/shell commands in the bat file then try executing it then it definately hangs at proc.waitFor();
    Even "cmd.exe /C C:\\test.bat" hangs... if the commands are more...
    Is this some sort of bug? or am i doing anything wrong? I tried searching for solution on the net and search forums... but couldnt find a solution for the same.. not sure where i missed, what i missed...
    Incase some one finds a solution.. do post it here...
    Message was edited by:
    amadas

  • How to extract  icon from windows exe  in java

    I have a windows ex e file which has icons , how can i extract from
    my java code? Where can i find a example code for doing this.

    You could do it by JNI-invoking into the dll, fetch the icon through LoadIcon, draw the icon onto a jawt drawing surface, return the pixel data of the icon to the java app or whatever. A lot of work for a little more than a thousand pixels. My advice would be to put the icon in the jar file instead, if that's an option.
    Regards,
    Nille

  • How do you access external .exe within Java?

    Say I wanted to feed a command to a .exe, right? How would go about doing that in Java and is there a cross-platform method or does it vary?

    helplessguyhelp wrote:
    tlgkumar,
    Hi can you help me to solve a problem??Dude, just start a new thread with your question, and whoever sees it and finds it worth their time will answer.

  • Executing an HTML file within java program

    I want my java code to be able to open/execute an HTML file that I have. How do you do this?
    Thanks.

    You can display html in a java app, but it is not so simple to run a browser. What you want to look up is the WebBrowser class. Here is an excerpt from some code of mine that displays a url in the browser app in a panel, but there's some chaff in my code you would not be interested in (I'm using a card layout). You're better off loocing up org.jdesktop.jdic.browser which contains the WebBrowser class    /**
         * Reveal the container with the browser display. The browser display is
         * currently hidded using a CardLayout, so it is a simple matter to swap
         * displays; however, we put off actually loading the web page until the
         * first time the display is revealed.
         * @return true if the URL could be resolved and the given web page
         * displayed.
        public boolean showBrowser(
            java.net.URL pURL )
            // See if the web page component has not initialized.
            if ( pWebBrowser == null )
                pWebBrowser = new WebBrowser();
                pBrowserPane.setViewportView( pWebBrowser );
            if ( aLastURLVisited == null || ! aLastURLVisited.equals( pURL ) )
                pWebBrowser.refresh();
                pWebBrowser.setURL( pURL );
                aLastURLVisited = pURL;
            pDualLayout.show( pDualPanel, BROWSER_PANEL );
            return true;
        }

  • Executing DOS command from within java.

    I have an XML file and an XSLT stylesheet.
    I want to process this XML file using XSLT stylesheet from java. Using saxon.
    Here is the java class I wrote --
    class DOSCommand {
    public void exec_command(String[] cmd) {
    try {
    Process child = Runtime.getRuntime().exec(cmd);
    } catch (IOException e){
    System.out.println("Error");
    System.out.println(e.getMessage());
    finally{
    System.out.println("Finally");
    In my servlet class I am instantiating the DOSCommand object and calling the method
    DOSCommand d = new DOSCommand();
    String[] c = {  "c:\\Program Files\\saxon\\saxon.exe", "-o",
    "PO.html", "ePO.xml", "POE.xsl"
    d.exec_command(c);
    But I am not getting results. It does not give any error. But does not process the XML file and the Date/timestamp of PO.html does not change.
    I know that Definition/Creation of DOSCommand object is not necesssary here. But we can disregard it.
    Please let me know where I am going wrong !
    Avinash.

    Probably where you are going wrong is in failing to specify your working directory, so your command can't find "PO.html" and so on in the default working directory for that command. But that's not really the answer. The answer is not to do it in that way in the first place. Saxon has a Java API and its documentation has a section entitled "Embedding Saxon in an application".

  • Executing vbscript from within java

    Hi,
    Does anyone knows a way to execute a vbscript from within java and capture its output.
    thanks

    Do you mean emulate an interpreter?

  • A problem in executing exp.exe through Java

    while implementing oracle schema export I am facing problem in executing the exp.exe from JAVA. Please see sample code below.
    Process p=null;
    ProcessBuilder pb = new ProcessBuilder ("exp.exe","username/password@dbinstance", "owner=pr01",
    "file=e:/temp/pr98.dmp","log=e:/temp/pr98.log","compress=y","grants=n","STATISTICS=COMPUTE");
    try{
    p = pb.start();
    catch(Exception e){
    System.out.println("Error="+e.getMessage());
    where pr01 - name of schema to export.
    With this code, the actual export of the project starts only after Java application is closed and not immediately on the click of a button.
    I have used Runtime.exec() tooo...The same problem is there..
    Any solution?

    HI
    Did you fix this problem with svrmgr. I have exactly the same problem and I am runing redhat 7.2 and oracle 8.1.6
    Thanks, Jason

  • How to execute SAPgui.exe from java code

    Hi All,
    Can any one provide me the exe file name of SAP GUI related.
    I need to call the SAP GUI related exe file from java.
    i tried with a small java prog which executes the exe files.
    it works fine with notepad.exe,javac.exe . But i am unable to execute the SAPgui.exe.
    This is my java code
    try{
         Runtime rt=Runtime.getRuntime();
    //String str= "C:
    WINNT
    system32
    notepad.exe";
    //Process pp=rt.exec("C:
    j2sdk1.4.2_08
    bin
    javac");
    Process pp=rt.exec("C:
    Program Files
    SAP
    FrontEnd
    SAPgui
    SAPgui.exe");
    BufferedReader br=new BufferedReader(new InputStreamReader(pp.getErrorStream()));
                         String line;
                         while ((line = br.readLine()) != null) {
                             System.out.println(line);
              }catch(Exception e){
                   System.out.println(e);
    and may i pass any additional parameters inorder to invoke this exe.
    Please share your ideas abt  this problem.
    Its Urgent PLZ
    Adv Thanks
    Regds
    Phani.

    hi Rajesh,
    here my complete code:
              try{
                   Runtime rt=Runtime.getRuntime();
    //               String str= "C:\Programmi\SAP\FrontEnd\SAPgui\saplogon.exe";
                   String str= "C:\Programmi\SAP\FrontEnd\SAPgui\Sapgui.exe 10.113.10.201 00";
                   //               Process pp=rt.exec("C:\j2sdk1.4.2_08\bin\javac");
                   Process pp=rt.exec(str);
                   BufferedReader br=new BufferedReader(new InputStreamReader(pp.getErrorStream()));
                   String line;
                   while ((line = br.readLine()) != null) {
                   System.out.println(line);
                   }catch(Exception e){
                   System.out.println(e);
    Please note that system number is only two digit and in your case is 00.
    Another important think, i'm using the italian version of windows, so the program directory is c:\programmi, please change into c:\program files, or you can modify your code to be language indipendend using an system environment variable (if exist).
    Hope this help
    Francesco

  • Building java executable for windows

    Well, actually I have two qestions:
    1) how it is possible to build executable running under windows using usual Java tools, e. g. ant or something like this?
    2) if I'm using VS.NET I can't compile files wich import javax. ... etc. classes, what I should to in order to import them?
    Any suggestions welcome.

    Well, actually I have two qestions:
    1) how it is possible to build executable running
    You want a .exe at a guess, search the forums.
    All the regs. have answed this many many many times, and some very good answers exist on the forums.
    Normally, when people ask this, they really need to read:
    http://java.sun.com/docs/books/tutorial/jar/
    http://java.sun.com/products/javawebstart/
    But sometime (not very ofton) a ".exe" is needed:
    http://gcc.gnu.org/java/
    http://www.excelsior-usa.com/jet.html
    under windows using usual Java tools, e. g. ant or
    something like this?Sure, make a new task. For GCJ this would be very easy.
    2) if I'm using VS.NET I can't compile files wich
    import javax. ... etc. classes, what I should to in
    order to import them?Are you compiling to .NET or to Java Byte Code.
    If its Java Byte Code, I have no idea, if its .NET the below might work
    http://classpath.org
    http://www.ikvm.net/

  • Executing Windows EXE program through JNLP

    Hello,
    I am trying to execute Windows .exe and dlls through Java web start/JNLP but unable to implement successfully. I tried by creating the content (exe and dlls) as a jar file and added as native resource library in the JNLP but not sure how to call the exe program?
    Any help or sample code is much appreciated.
    Thanks,
    Edited by: b_raja on Feb 21, 2008 2:58 PM

    I am trying achieve similar thing using JNLP. So far in my research, I think you need to use the installer-desc and have an implementation in ExtensionInstallerService.
    Refer to the JNLP specifications. I havent tried to implement that yet, but will update here if I get anywhere.
    Cheers

  • Invoking a registered executable in windows thru java ..

    Hi ,
    My requirement is that I need to invoke adobe (acroRd32.exe) thru JAVA passing some command line argument to it.
    I can invoke it using
         try
              Runtime runTime = Runtime.getRuntime();
              Process process = null;
              String command = "D:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /p <filename>";
              process = runTime.exec(command);
         catch (Exception e)
              e.printStackTrace();
    but for this I need to know the exe path.
    The problem is that I don't want to read the registries to determine the path .. is there any way out for this?
    The Clue ..
    When I type a registered exe name in windows run command then it opens automatically. Can I invoke the same process thru java also?
    Any help in this regard will be highly appreciated ..
    TIA,
    -Arun

    Runtime r = Runtime.getRuntime();
    Process pro = null;
    try
      pro = r.exec("D:\\Program Files\\Adobe\\Acrobat 5.0");
      pro.waitFor(); //Program waits until Adobe is terminated.
    catch(Exception ex)
      System.out.println("Could not execute Adobe");
    }Hope this helps.
    Vijay :-)

  • Compiling JAVA into Windows .exe files

    Hi,
    Here's an easy question - how do you compile JAVA source into Windows .exe files (as opposed to class files with bytecode in them). I imagine there is a third-party product out there somewhere?

    A Bayesian network is a mathematical representation of logical inference.
    A very simple example has two nodes: "has tail" and "is horse", connected by a single link. If we know "is horse" is true, then it nearly always follows that "has tail" is also true. This is called modus ponens in logic. If we know "has tail" is true, then "is horse" might be true, but it might not. To infer that "is horse" is true in such a case is to commit what is called the fallacy of affirming the consequent, in logic. However, using Bayes' theorem, which would require that we know some general information about the prevelance of horses among tailed animals, and the general prevalence of horses among things in general, we can measure the exact increase in the probability that "is horse" is true that results from our knowing "has tail" to be true.
    For more information, see http://www.bayesian.org
    The classic book on the subject is Judea Pearl, Probabilistic Reasoning in Intelligent Systems.

  • Setting Windows Envirnoment variables within Java code!!

    Hello All,
    How to setup Windows envirnoment variables within Java code dynamically.
    int customer = jList1.getSelectedIndex();
    System.out.println(customer);
    switch (customer)
    case 0:
    System.out.println("HOME1");
    break;
    case 1:
    System.out.println("HOME2");
    break;
    case 2:
    System.out.println("HOME3");
    break;
    case 3:
    System.out.println("HOME4");
    break;
    default:
    System.out.println("HOME5");
    break;
    }

    set windows %HOME% variableWhat is it?
    A system-wide resource? Something pertinent to the processes of a given user? Or does it apply only to your Java process?

  • Can AIR execute Windows .EXE files?

    Can AIR execute Windows .EXE files?

    hi
    you can now implement a standard windows installer (ie a native installer, rather than the AIR installer) when users install your AIR app. Not sure if there's an option to do this in flex/flash builder but it can be done via command line.
    eg:
    adt -package -storetype pkcs12 -keystore myCert.p12 -target native NativeProcessTest.exe NativeProcessTest-app.xml NativeProcessTest.swf NativeApps/Windows/bin/echoTestWindows icons
    or try this handy packager:
    http://www.webkitchen.be/package-assistant-pro/

Maybe you are looking for

  • Database in Archivelog mode

    Hi All, I have oracle 9.2.0.6 at my workplace.right now my database running in ARCHIVELOG MODE. I want to set it to NOARCHIVELOG MODE. can I do on the fly? in other way, Do I need to shutdown and restart database? Any help will be appreciated. Thanks

  • Oracle XML Parsers DOM vs SAX

    I have many huge XML formated data files I'm trying to importing into Oracle tables. The DOM model with XSL stylesheets will work great because many of the files XML element tags do not match the Oracle table column names. The problem is that the XML

  • Just got ipod of my mate no installer disk

    can anyone help me how can i get my PC to recognise my Ipod nano 1gb I'e downloaded itunes but can't get my p to find my ipod

  • Restore another version of iTunes

    When I recently upgraded my iTunes software, I stupidly reverted to a previous version of iTunes.  The previous had 1561 songs in it.  The current (at the time) had 2,300+ which means that I now seem to have almost 1,000 songs.  PLEASE HELP !!! Have

  • How to press "Call" or "Send" button while you're talking??

    Normally, cell phones have a "Call" or "Send" button outside the screen. So you when you're talking to someone, you'll be able press "Call" button. For example, I called a company and they needed me to press the number xxxxxxxxxxx and press "Send" or