Execute a .exe file I created?

I've written a c++ file and compiled it; I now have an executable. I decided it'd be nice to have a pretty interface, and I thought it'd be easy to throw one together in java, and just call the executable from my java program. However, I've run into some trouble trying to use the Runtime.exec() command.
I gather that the exec() command is good for shell commands, and evidently doesn't work for programs like mine. I was hoping to find a call similar to system(...) in c++, where it would execute the passed parameter as if it were on the command line (I know that's not what Runtime.exec() does). Could anybody tell me how to run an executable I've written from within java? Thanks.
(this is what I wrote:)cmd[0] = "cmd.exe";
cmd[1] = "/C" ;
cmd[2] = "VBDoc";
Process proc = runtime.exec(cmd);where "VBDoc" is the program I've written already, and I capture the output of the call.
I get:
ERROR>'VBDoc' is not recognized as an internal or external command,
ERROR>operable program or batch file

Several things:
(1)I've included the file extension, and now it hangs - which is odd, because I included a "streamGobbler" thread as was encouraged in that write up to "promptly ... read the output stream of the subprocess". At least it's a different problem now. =)
(2)Mark, you indicated in your first post that the entire path needed to be explicitly included, which I'm not convinced of: as I mentioned earlier, I included the executable's directory in the system path variable, so it can be executed from anywhere
(3)Before I noticed all the latest replies to this question, I got Visual Studio installed on my computer and whipped together a VB GUI that solves my problem. <=\
I'm still interested as to how I can execute the file, though. If any one is still interested, here's the code:import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class htmlGUI extends JFrame
    static private final String newline = "\n";
    static Runtime runtime;
    public htmlGUI()
        super("htmlGUI");
        //Create the log first, because the action listeners
        //need to refer to it.
        //Actually, I don't really use this for anything important;
        //I used a java demo for my framework, cause I wasn't sure
        //how to open files from a dialog-style box.
        final JTextArea log = new JTextArea(5,20);
        log.setMargin(new Insets(5,5,5,5));
        log.setEditable(false);
        JScrollPane logScrollPane = new JScrollPane(log);
        //Create a file chooser
        final JFileChooser fc = new JFileChooser();
        //Create the open button
        ImageIcon openIcon = new ImageIcon("images/open.gif");
        JButton openButton = new JButton("Convert a File...", openIcon);
        openButton.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                int returnVal = fc.showOpenDialog(htmlGUI.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    String fileName = file.getName();
                    //slap a comment in the textarea
                    log.append("Opening: " + file.getName() + "." + newline);
                    runtime=Runtime.getRuntime();
                    try
                              String osName = System.getProperty("os.name" );
                              String[] cmd = new String[3];
                              if( osName.equals( "Windows 2000" ) || osName.equals( "Windows NT" ) )
                                   cmd[0] = "cmd.exe";
                                   cmd[1] = "/C" ;
                                   cmd[2] = "VBDoc.exe";
                              else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) )
                                   cmd[0] = "command.com" ;
                                   cmd[1] = "/C" ;
                                   cmd[2] = "VBDoc.exe";
                           else
                                System.out.println(osName);
                         Process proc = runtime.exec(cmd);
                              // any error message?
                              StreamGobbler errorGobbler = new
                                   StreamGobbler(proc.getErrorStream(), "ERROR");
                              // any output?
                              StreamGobbler outputGobbler = new
                                   StreamGobbler(proc.getInputStream(), "OUTPUT");
                              // kick them off
                              errorGobbler.start();
                              outputGobbler.start();
                              // any error???
                              int exitVal = proc.waitFor();
                              System.out.println("ExitValue: " + exitVal);
                         catch(IOException ioe)
                              System.out.println(fileName);
                         //     System.err.println(ioe);
                              ioe.printStackTrace();
                         catch (Throwable t)
                              t.printStackTrace();
                } else {
                    log.append("Open command cancelled by user." + newline);
        //Create the save button
        ImageIcon saveIcon = new ImageIcon("images/save.gif");
        JButton saveButton = new JButton("Save a File...", saveIcon);
        saveButton.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                int returnVal = fc.showSaveDialog(htmlGUI.this);
                if (returnVal == JFileChooser.APPROVE_OPTION)
                    File file = fc.getSelectedFile();
                    //this is where a real application would save the file.
                    log.append("Saving: " + file.getName() + ". (Yeah, Right)" + newline);
                else
                    log.append("Save command cancelled by user." + newline);
        //For layout purposes, put the buttons in a separate panel
        JPanel buttonPanel = new JPanel();
        buttonPanel.add(openButton);
        buttonPanel.add(saveButton);
        //Explicitly set the focus sequence.
        openButton.setNextFocusableComponent(saveButton);
        saveButton.setNextFocusableComponent(openButton);
        //Add the buttons and the log to the frame
        Container contentPane = getContentPane();
        contentPane.add(buttonPanel, BorderLayout.NORTH);
        contentPane.add(logScrollPane, BorderLayout.CENTER);
    public static void main(String[] args)
        JFrame frame = new htmlGUI();
        frame.addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
        frame.pack();
        frame.setVisible(true);
class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
        this.is = is;
        this.type = type;
    public void run()
        try
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line=null;
            while ( (line = br.readLine()) != null)
                System.out.println(type + ">" + line);
            catch (IOException ioe)
                   ioe.printStackTrace();
}Thanks!

Similar Messages

  • Execute another exe file by my VI

    Hello,
    I am trying to execute anothe exe file, which was not created using LabView, from my VI.
    Is it possible? How could I do it?
    Thank you

    Use the System Exec function. Under Connectivity -> Libraries & Executables palette.

  • 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();
    ...

  • How to execute one .exe file with as3 in air ?

    Hi
    How to execute one .exe file with as3 in air?
    I want do this work without fscommand .
    plize help me .

    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.

  • How to execute a exe file using javascript on app window.load.

    How to execute a exe file using javascript on app window.load.

    Hi sb00349044,
    As I have already mentioned in multiple replies to your previous questions, the SUMO forums focuses on providing help to end users with usage-questions and issues.
    For developer-related questions, please refer to one of the many resources readily available that I have linked to in the past:
    * [https://developer.mozilla.org/en-US/Firefox_OS MDN]
    * [http://stackoverflow.com/questions/tagged/firefox-os StackOverflow]
    * [https://lists.mozilla.org/listinfo Mozilla Mailing Lists]
    - Ralph

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

  • How to execute a EXE file in java?

    Hi!All
    as title
    Can I use Java to call any EXE file.
    I need your help!!

    ~~~Use This~~~~
    try{
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(
    "C:/Program
    Program Files/InternetExplorer/IEXPLORE.EXE
    http://192.168.1.101/index.jsp");
    why has private IP there?
    } catch (IOException e) {
    e.printStackTrace();
    }I and he want to a file which could run as .exe file.

  • Psexec shows Access denied when i execute a .exe file on a remote machine

    Hi All,
    I am using Psexec application to run exe on multiple remote machines in the domain. When i run the the .EXE i get the error message saying access is denied.
    I am running this script against agents in a list.
    Below is the script i am running in the batch:
    "C:\Windows\system32\PsExec.exe" @C:\Test.txt cmd
    1. I am first connecting to the cmd of the remote computer and it connects successfully.
    2. When i enter the .exe file location on the command prompt (which is also in a shared drive but in the same domain).
    3. I ran the batch file as Run as administrator
    4. I am itself a member of the Domain admins and Administrators group of the domain.
    5. Turned off firewall on both sides.
    6. Turned off UAC fully as per the below MS article - http://technet.microsoft.com/en-us/library/cc709691(v=ws.10).aspx
    7. Pressed shift and right click so i will get the Run as option and mentioned different domain admins user account and password.
    Below is the screenshot for your reference: 
    Restated both the machines after doing these changes. But still the same issue.
    But still i get access is denied. Can anyone please help.
    Gautam.75801

    Few days back when i used to run the same task in this Access is denied mode its self. My destination server used to give a Audit failure event log as below.
    Now a days this event log does not come.
    Can this help for analysis.
    Subject:
    Security ID:
     Domain name\My username
    Account Name:
     Gautamr
    Account Domain:
    My Domain
    Logon ID:
     0x234992
    Object:
    Object Server:
    Security
    Object Type:
     File
    Object Name:
     C:\Windows\System32\eventvwr.msc
    Handle ID:
     0x0
    Process Information:
    Process ID:
     0x17e0
    Process Name:
     C:\Windows\System32\mmc.exe
    Access Request Information:
    Transaction ID:
    {00000000-0000-0000-0000-000000000000}
    Accesses:
     READ_CONTROL
    SYNCHRONIZE
    WriteData (or AddFile)
    AppendData (or AddSubdirectory or CreatePipeInstance)
    WriteEA
    ReadAttributes
    WriteAttributes
    Access Reasons:
    READ_CONTROL:
    Granted by
    D:(A;;0x1200a9;;;BA)
    SYNCHRONIZE:
     Granted by
    D:(A;;0x1200a9;;;BA)
    WriteData (or AddFile):
    Not granted
    AppendData (or AddSubdirectory or CreatePipeInstance):
    Not granted
    WriteEA:
     Not granted
    ReadAttributes:
    Granted by ACE on parent folder
    D:(A;;0x1301bf;;;BA)
    WriteAttributes:
    Not granted
    Access Mask:
     0x120196
    Privileges Used for Access Check:
    Restricted SID Count:
    0
    Gautam.75801

  • Which is the function to execute an .exe file in java

    in languages like c we can create .exe's of files.but in java we cant do that.
    i wanted to implement a software which i compiled in c using java.in c
    i created an .exe of the file and distributed it but in java i dont find any such
    method of creating exe as i would like to distribute the software.please help
    me out on this
    please also give me the name of the function using which i can exexute an
    .exe file

    No problem - it's just that I wanted to alert people to the fact that
    there was another thread. Otherwise It can get very confusing, very
    fast. (The CAPS were unnecessary, sorry about that.)
    Welcome to the forums!

  • Executing a .exe file brings up the DOS console

    Hello,
    My Java app calls a native program to run. I made an executable JAR file so users can just double-click on it to start the app. It all looks very nice except that, when my app calls the
    native program, a DOS console pops up on the screen. It closes itself when the process is
    finished but I'm wondering if there's a way to suppress the DOS console from popping up so
    that DOS consoles won't keep flashing on the screen while the app is running.
    The code I use to call the native program is as follows:
    Runtime rt = Runtime.getRuntime();
    Process child = rt.exec("someProg.exe");
    Thanks in advance for any help.

    First of all, thank you very much for your reply. I have checked the command associated with JAR files in my Windows system, it is already running it with javaw but random DOS consoles still flash all over the screen... Any other ways to work around this problem? Thanks.

  • Creating win 32 exe files from java class files

    Hi I am using windows 2000.
    I have developed a java swing gui application that has about 10 class files. I downloaded the microsoft sdk for java 4.0 for converting all my class files into a single .exe file. I used jexegen in this SDK to do this process. But when I double click the exe file, it just pops up and closes instantenously without showing my startup frame.
    Can anyone help ?

    There is no Microsoft solution for this until you get J#, change your program
    (J# is a little bit different that java but not much, it's closer to Java than C#)
    and then compile to Win32 .exe.
    For the refrence list of all Java to Native code compilers, check this page:
    http://www.geocities.com/marcoschmidt.geo/jcomp.html#native :
    Different from "normal" compilers (like javac or jikes), native compilers do not create bytecode files
    (.class) that are interpreted by a Java Virtual Machine but native executables (like .exe files on
    Windows). "How do I create an EXE from Java?" is a very frequently asked question in newsgroups
    like comp.lang.java.programmer, native compilers are the answer. Some native compilers are listed
    below, check them out.

  • Reg : Executing .exe file from application server

    Dear Experts,
                        i have a requirement to execute an .exe file from application server,i tried with method CL_GUI_FRONTEND_SERVICES=>EXECUTE but it executes .exe file from presentation server only.can
    anyone kindly clarify to execute .exe file from application server?
    Thanks in advance,
    Sujay

    Hi,
    Did you search before posting?
    Re: Execute a .exe file present in the Application Server
    Vikranth

  • Problems executing exe file outside vignette(HAL)

    Hi, when trying to execute my exe file generated with vignette I'm getting an error:
    C:\WINDOWS\system32\cmd.exe - cas33.bat
    The NTVDM CPU has encountered an illegal instruction
    CS:05a7IP:016b OP:63 65 64 20 77 Chose 'Close' to terminate the application.
    The thing is that I've executed it before in other computer and it was working. But now I've to execute it in other computer where I have to specify other parameters in my .ini file ( as server, user, password, filename...)
    Any idea??
    Thank you

    Hi,
    No I just write them in the ini file(replacing the old values with the new ones).
    I don't have dll in the folder. It was working in the other computer by just executing the .bat file...I don't know what is happening know.
    Thank you so much

  • Problem with executing .exe file

    I am executing a .exe file in sun studio (Web Project) .... but it generate Control Access Exception, File Permission <<ALL FILES>> Denied . But the same command execute with simple java file and in DOS command....
    kindly someone give me help
    Thanks

    You have posted your message on the Sun Java Studio Creator forum. I believe you need to repost your message on a Sun Studio forum. Please see http://developers.sun.com/prodtech/cc/community/index.jsp.

Maybe you are looking for

  • IPod and Windows Partition

    Hello, I've recently purchased the latest generation MacBook with a 4th generation iPod Nano. A couple of weeks ago I had my iPod connected to the MacBook while it was running Boot Camp (on Windows XP Service Pack 2) and soon after this I noticed tha

  • Windows 7 Desktop won't run

    I have a palm centro and recently purchased a new dell laptop running Windows 7 64 bit.  Installed the Desktop 6.2.  Worked for a couple of days.  Suddenly would not load on startup with an error message.  Finally got through to a Palm tech through A

  • External hard drive connected to mac Mini is having problems and won't repair

    Hi, Thanks in advance for any support. My Mac mini (OS 10.7.5) isn't reading the external drive correctly and sometimes doesn't find it at all. When it does find the drive, some folders which I know to be large show up as empty (not always the same f

  • Substring() Issue

    Hi, I have a string with the following content: String1 String2 With other words: "\n\n\n\nString1\nString2" How can I extract String1 & String2 from the whole string? Thanks in advance!

  • RAR - Risk Analysis - Permission Level - V_VBAK_AAT||AUART - Error

    I have a trouble related with risk analysis at permission level, when the V_VBAK_AAT||AUART is activated in two functions of my customized GRC rule-set (VIRSA_CC_FUNCPRM) for controlling some "document types" for tcodes VA01 and VA02. When I execute