Class to call other exe

hello!
can i create a java program that can call other .exe file???
how????
thanks.

Try this:
Runtime.getRuntime().exec("rundll32
url.dll,FileProtocolHandler " filename);Worked very well for me. It's like double-clicking a
file in explorer. Don't know if it works with an exe
though...try it ;-)I wouldn't recommend that way. If you're trying to "run" a ".doc" file - that isn't a process. A process is a .exe file, such as Word.exe (or whatever MS Word's application executable is). Let the shell handle it:
Runtime.getRuntime().exec("cmd.exe /C start " + filename);
where filename is a path to a .doc file, for example.
And no, there's no way from pure Java to automate the child process such as making it insert text. You'd need to program against COM (Microsoft's Component Object Model) to do that, which you can do with a 3rd-party Java-to-COM bridge (search the net for "Java COM bridge" for starters). And you'd have to know Word's COM API.

Similar Messages

  • Errors in a Java class when calling other methods

    I am giving the code i have given the full class name . and now it is giving the following error :
    Cannot reference a non-static method connectDB() in a static context.
    I am also giving the code. Please do help me on this. i am a beginner in java.
    import java.sql.*;
    import java.util.*;
    import DButil.*;
    public class StudentManager {
    /** Creates a new instance of StudentManager */
    public StudentManager() {
    Connection conn = null;
    Statement cs = null;
    public Vector getStudent(){
    try{
    dbutil.connectDB();
    String Query = "Select St_Record, St_L_Name, St_F_Name, St_Major, St_Email_Address, St_SSN, Date, St_Company, St_Designation";
    cs = conn.createStatement();
    java.sql.ResultSet rs = cs.executeQuery(Query);
    Vector Studentvector = new Vector();
    while(rs.next()){
    Studentinfo Student = new Studentinfo();
    Student.setSt_Record(rs.getInt("St_Record"));
    Student.setSt_L_Name(rs.getString("St_L_Name"));
    Student.setSt_F_Name(rs.getString("St_F_Name"));
    Student.setSt_Major(rs.getString("St_Major"));
    Student.setSt_Email_Address(rs.getString("St_Email_Address"));
    Student.setSt_Company(rs.getString("St_Company"));
    Student.setSt_Designation(rs.getString("St_Designation"));
    Student.setDate(rs.getInt("Date"));
    Studentvector.add(Student);
    if( cs != null)
    cs.close();
    if( conn != null && !conn.isClosed())
    conn.close();
    return Studentvector;
    }catch(Exception ignore){
    return null;
    }finally {
    dbutil.closeDB();
    import java.sql.*;
    import java.util.*;
    public class dbutil {
    /** Creates a new instance of dbutil */
    public dbutil() {
    Connection conn;
    public void connectDB(){
    conn = ConnectionManager.getConnection();
    public void closeDB(){
    try{
    if(conn != null && !conn.isClosed())
    conn.close();
    }catch(Exception excep){
    The main error is occuring at the following lines connectDB() and closeDB() in the class student manager. The class dbutil is in an another package.with an another file called connectionManager which establishes the connection with DB. The dbutil has the openconnection and close connection methods. I have not yet written the insert statements in StudentManager. PLease do Help me

    You're doing quite a few things that will cause errors, I'm afraid. I'll see if I can help you.
    The error you're asking about is caused by the following line:
    dbutil.connectDB();
    Now first of all please always ensure that your class names begin with capital letters and your instances of classes with lowercase letters. That's what everybody does, so it makes your code much easier to follow.
    So re-write the couple of lines at the beginning of your dbutil class like this:
    public class Dbutil {
    /** Creates a new instance of Dbutil */
    public Dbutil() {
    Now you need to create an instance of dbutil before you can call connectDB() like this:
    Dbutil dbutil = new Dbutil();
    now you can call the method connectDB():
    dbutil.connectDB();
    The problem was that if you don't create an instance first then java assumes that you are calling a static method, because you don't need an instance of a class to call a static method. If it was static, the method code would have been:
    public static void connectDB(){
    You have a fine example of a static method call in your code:
    ConnectionManager.getConnection();
    If it wasn't a static method your code would have to look like this:
    ConnectionManager connectionManager = new ConnectionManager();
    connectionManager.getConnection();
    See the difference? I also know that ConnectionManager.getConnection() is a call to a static method because it begins with a capital letter.
    Anyway - now on to other things:
    You have got two different Connection objects called conn. One is in StudentManager and the other is in Dbutils, and for the moment they have nothing to do with each other.
    You call dbUtil.connectDb() and so if your connectDb method is working properly you have a live connection called conn in your dbUtil object. But the connection called conn in StudentManager is still null.
    If your connection in the dbUtil object is working then you could just add a line after the call to connectDb() in StudentManager so that the StudentManager.conn object references the dbUtil.conn object like this:
    dbutil.connectDB();
    conn = dbUtil.conn;

  • Call other exe in labview

    Hi all
    how to call an exe created in vc++ in labview...

    You can use system Exec function from Connectivity-->Libraries and Executables Palette. You can call your exe, the same way you invoke it from command prompt.
    Thanks 

  • Passing values and calling other classes?

    Hello all.
    I have 2 classes(separate .java files). One is a login class and the other is the actual program. Login class(eventually exe file) should open the other class and pass the login parameters if you know what I mean. Is this possible, or do the 2 classes need to be part of one file?
    Thanks alot
    Milan D

    Login class can be another class in another file
    wht u have to do is to make an instance of login class in the class u want to use that class
    like login lg = new Login();
    and call method of login class
    lg.setUser(username);
    where setUser(String user); is a method of login class
    this way u can pass the parameters to login class
    i hope this might be helpful
    regards
    Moazzam

  • Is Two Classes that call methods from each other possible?

    I have a class lets call it
    gui and it has a method called addMessage that appends a string onto a text field
    i also have a method called JNIinterface that has a method called
    sendAlong Takes a string and sends it along which does alot of stuff
    K the gui also has a text field and when a button is pushed it needs to call sendAlong
    the JNIinterface randomly recieves messages and when it does it has to call AddMessage so they can be displayed
    any way to do this??

    Is Two Classes that call methods from each other possible?Do you mean like this?
       class A
         static void doB() { B.fromA(); }
         static void fromB() {}
       class B
         static void doA() { A.fromB(); }
         static void fromA() {}
    .I doubt there is anyway to do exactly that. You can use an interface however.
       Interface IB
         void fromA();
       class A
         IB b;
         A(IB instance) {b = instance;}
         void doB() { b.fromA(); }
         void fromB() {}
       class B implements IB
         static void doA() { A.fromB(); }
         void fromA() {}
    .Note that you might want to re-examine your design if you have circular references. There is probably something wrong with it.

  • How to execute or call other application

    I have doubt in executing or calling any exe file using java application.
    For example: i have a button. If i click on that button, then any application (eg. any exe file, any program file, etc) will execute and come out in the different frame. Now, i don't know how to make the coding.
    I need the helps. Please give me any code or ideas.
    Thanks very much

    Sorry. if you are writing a sample program just to get a feel of Java, then the following is sufficient. Note that I have added "throws Exception" after the "main" method signature.
    import javax.swing.JOptionPane;  // import class JOptionPane
      public class Welcome4 {
      // main method begins execution of Java application
         public static void main( String args[] ) throws Exception
            JOptionPane.showMessageDialog(
               null, "Welcome\nto\nJava\nProgramming!" );
             String command = "d:\\test\\test.bat";
         Process p = Runtime.getRuntime().exec(command);
         p.waitFor();
         System.out.println("done");
            System.exit( 0 );  // terminate application
         }  // end method main
      }  // end class Welcome4

  • How can I call external exe in java

    Hi ,
    Is It Possible to call external exe in java.
    I read Runtime.exe("some exe") but actually my exe expects some input to process for that how can i pass the input to my exe and how can get the response from exe to my java class.
    any sample code is welcome.
    Thanks
    Babu H

    example
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.io.*;
    public class RuntimeExample extends JFrame {
        private JTextArea textArea;
        private JTextField textField;
        private PrintWriter writer;
        public RuntimeExample()
            init();
            initProcess();
        public void init()
            textArea = new JTextArea(20, 80);
            textArea.setEditable(false);
            textField = new JTextField(30);
            textField.addKeyListener(new KeyAdapter()
                public void keyPressed(KeyEvent event) {
                    if (event.getKeyCode() == KeyEvent.VK_ENTER)
                        if (writer != null)
                            textArea.setText("");
                            writer.print(textField.getText() + "\r\n");
                            writer.flush();
                            textField.setText("");
            Container container = getContentPane();
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportView(textArea);
            container.add(scrollPane, BorderLayout.CENTER);
            container.add(textField, BorderLayout.SOUTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            textField.grabFocus();
            setVisible(true);
        public static void main(String[] args) {
            new RuntimeExample();
        public void initProcess()
            Runtime rt = Runtime.getRuntime();
            try
                //Process p = rt.exec(new String [] {"cmd", "/C", textField.getText()});
                //textArea.setText("");
                //textField.setText("");
                Process p = rt.exec("cmd");
                writer = new PrintWriter(p.getOutputStream());
                Thread thread1 = new Thread(new StreamReader(p.getErrorStream()));
                Thread thread2 = new Thread(new StreamReader(p.getInputStream()));
                thread1.start();
                thread2.start();
                System.out.println("Exit Value = " + p.waitFor());
            catch (Exception ex)
                textArea.append(ex.getMessage());
                ex.printStackTrace();
        public class StreamReader implements Runnable
            InputStream is;
            public StreamReader(InputStream is)
                this.is = is;
            public void run()
                try
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    String data;
                    while ((data = reader.readLine()) != null)
                        textArea.append(data + "\n");
                    reader.close();
                catch (IOException ioEx)
                    ioEx.printStackTrace();
    }you can pass input to the exe by using getOutputStream() from Process and get the output from getInputStream() from Process

  • Class names, 'HelloWorldApp.java.exe' are only accepted if annotation -----

    {font:#mce_temp_font#}Class names, 'HelloWorldApp.java.exe', are only accepted if annotation processing is explicitly requested.
    1error
    In continuation to reply "All you should be doing is accessing the .exe files in/bin. That means adding that directly to your PATH so that the os------to find the .exe files.
    I,d recommend-------DOS file path convention"(e.g. "C\Progra~1\Java\jdk1.6.0\bin")------
    Question: May i ask you -there are so many .exe files under the folder
    "C\Progra~1\Java\jdk1.6.0\bin" such as
    java.exe, jar.exe, appletviewer.exe -------etc Which files are you refering to?
    Suppose, java.exe is the correct file, if ENTER on following command
    in Command Prompt
    C:\Progra~1\Java\jdk1.6.0\bin\javac HelloWorldApp.java.exe
    (Here, My file name>>HelloWorldApp)
    i get Clas names, 'HelloWorldApp.java.exe', are only accepted if annotation processing is explicitly requested.
    1error
    Am i proceeding in the correct way? If correct, what to do next?
    damp{font}

    Work through the Tutorial:
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
    Your source file is called
        HelloWorld.javaIn the directory containing thes file you compile with
        javac -cp . HelloWorld.javaAnd run with
        java -cp . HelloWorldThere is no ".exe" anywhere.

  • About use exec to call java.exe!

    when i use the exec to call java.exe to run a class,
    a dos command window will be showed! The window appear until the java program completed~
    i always use "javac filename.java"
    ,"java filename"
    or "cmd.exe \c java filename"
    any method can run the class file but the dos command windows wont show?
    and also any method in cmd can do the same thing as Linux background process "&". Because when running a class, the cmd is locked until the java program completed.
    Thx~

    Use javaw if you dont want the dos prompt window.
    Use start if you dont want to block the current dos window. e.g.
    Start java my.class
    Start will start another native thread to run java.exe
    hope it helps.

  • Calling an exe but exe isnt generating files

    Hi
    I basically have a JButton that when pressed calls a java class that has a method to call an .exe.
    When the exe is called it is supposed to take a path name for a video and split the video into image files.
    The method is as follows:
            String commandArgs = "C:\\Test1 " + "C:\\video.mpg";
            try
                Runtime rt = Runtime.getRuntime();
                Process p = rt.exec(commandArgs);
                int exitVal = p.waitFor();
                System.out.println("Exit value = " + exitVal);
            catch (Throwable t)
                   System.out.println("Error thrown in method decodeMpeg()");
              }When I run this through NetBeans it says that it has run the exe but no files are generated.
    If I just put this method into a java file, javac it and run it in a console window it works fine.
    Does anyone know why I cant generate files through the NetBeans IDE?
    Im really stumped so any help would be great.
    Thanks

    Ok it was just a stupid thing that one of my friends pointed out. I had been looking for the files to be generated in the same location as the .exe
    Im very new to using NetBeans and didnt know that it actually outputs the files to the project file.

  • How do you use a main applet to call other child applets?

    Hello Everyone!
    I have created three separate applets that animate different colored walkers that walk across the web page with each applet doing what I need them to do. I need to create a main applet that displays a component that allows the user to select how many walkers(1-3) they would like to see displayed walking across the screen. The main applet should call only one walker applet if 1 is selected, call two applets if 2 is selected, or call all three applets if 3 is selected.
    My textbook has covered how to call other classes in an application but not a main applet calling other applets. I have gone through the tutorials but have not found anything related to what I need to do. Google didn't have any good ideas.
    Another possibility that would work would be to have one applet with each walker having its own method to be called based upon the selection. Then again, my textbook didn't cover calling methods within an applet.
    Any hints or suggestions would be greatly appreciated on these issue.
    Thanks.
    Unclewho

    Remember, an Applet is nothing more than a Panel (or JPanel for a JApplet) - basically an empty graphics container waiting for UI or graphics commands.
    You do not have a "main" applet as you do when you create an executable application which requires the 'main' method.
    The best thing to do, is simply do an HTTP Redirect to a page created with the desired number of "walkers". In your cause, the most you'd need is 3 walkers, so 4 pages - 1 redirect page, and then a page with 1 walker, a page with 2 walkers, and a page with 3 walkers.

  • How to convert the javasource file(*.class) to execute file(*.exe)?

    How to convert the javasource file(*.class) to execute file(*.exe)?
    thank you!

    Although i have seen a few programs (that are platform specific) that will embed a small jvm into an exe with your class file, it is generally excepted that you cannot create an executable file using java. The JAR executable file is probably the closest your going to get
    Pete

  • Conversion of a .jar OR a .class file into a .exe  file

    Can anyone tell me as how to convert a .jar OR a .class file into a .exe file
    I need to know as soon as possible.

    Okay I will tell you the steps:
    Look in the top right hand corner of the page.
    There should be a box with a red title line. Inside the
    title should be the letters 'S E A R C and H'.
    In the white part of th box should be a smaller line, in which you can type.
    type in "conversion .jar .class .exe" or some similar string.
    Then click on the button next to the text box.
    Read the page of results you get.
    Click on the first link and read what is said on the connecting page.
    If that doesn't help, use your browser's back button and click on the next link, and repeat util your question is answered.

  • Error while calling pscp.exe through a batch file which is called in SSIS Execute Process Task

    Hi,
    I am using Windows Server 2012 R2 Standard, SSIS 2012. I am trying to copy files from a remote location by calling pscp.exe through a batch file (FileCopy.bat at location M:\bin\) which is referenced in a SSIS Execute Process Task. My batch file content
    is,
    ECHO OFF
    echo. >> M:\Prod\bin\SourceFile_FileLog.txt
    echo %date% - %time% - Copy Start (XYZ_a201211155952avx0_69999.NOR.gz) >> M:\Prod\bin\SourceFile_FileLog.txt
    M:\ProdFiles\bin\pscp.exe -unsafe -scp -pw aaaaa myuser@sourceserver:/ABC_data/*.NOR.gz M:\Prod\FromMediation\
    echo %date% - %time% - Copy Complete >> M:\Prod\bin\SourceFile_FileLog.txt
    The error I am getting is 
    [Execute Process Task] Error: In Executing "M:\bin\FileCopy.bat" "" at "", The process exit code was "1" while the expected was "0".
    Exactly same setup but using Windows Server 2003 R2 Enterprise and SSIS 2005, this works fine and copies the files successfully.
    Please provide some guidance on this.
    Thank you!
    'In Persuit of Happiness' and ..... learning SQL.

    Hi,
    This is what I am getting while running the batch file from command prompt
    M:\bin\mttrb1>CDR_FileCopy
    M:\bin\mttrb1>ECHO OFF
    The system cannot find the path specified.
    The system cannot find the path specified.
    scp: M:\Prod\FromMediation\: Cannot create file
    scp: M:\Prod\FromMediation\: Cannot create file
    scp: M:\Prod\FromMediation\: Cannot create file
    The system cannot find the path specified.
    'In Persuit of Happiness' and ..... learning SQL.

  • After download itunes installation began in windowx xp near the end of the installation the message says: it was not possible to write the value to the key Software / Classes / .mpg / OpenWithList / iTunes / .exe. Already reinstalled 3 times and always sa

    After download itunes installation began in windowx xp near the end of the installation the message says: it was not possible to write the value to the key Software / Classes / .mpg / OpenWithList / iTunes / .exe.
    Already reinstalled 3 times and always says the same message.
    thank you

    Only two had virus on windows XP this week and wiped them with Avast. The itunes asked me to install the update, and so I did. but it always gives me that message.

Maybe you are looking for

  • Flash Player doesn't play smoothly and out of sync in full screen

    Hello! Everyone The flash player (11.2.202.235) does not play smoothly and in full screen audio and vidoe is out of sync.  I didn't use to have any problem at all, it only started about two weeks ago and since then despite trying various things (i.e.

  • [solved] Probems with gnome 3.4.1 power settings

    I have gnome 3.4.1 running on my netbook and I have some problems with power setting in past few days. When I close lid of netbook when it connected to AC power it goes to sleep but in settings i have $ gsettings get org.gnome.settings-daemon.plugins

  • Can't create a new user session with KDE

    Hi, when I select "Switch user" in KDE, and try to start a new user session, I get dropped to a lockscreen of the currently logged-in user. I first thought this was a KDM issue, but this still persists with SDDM. I'd post any relevant logs, but I'm n

  • I want to see the Folder or Album view

    I upgraded to Photo unknowingly and can't find my album or folder view in prefrences. 

  • Has anyone seen a Component that Creates a Transition Like This?

    Has anyone seen a Flash Component that creates a slide transition similar to this... http://www.silversea.com/ Looks like there is a looping background image and the other slides are loaded above it (hopefully via XML?) and the transition effect mayb