Executing any other applications from a java application

how can i execute or invoke other applications on the pc
from a java application?

Runtime.getRuntime().exec("dir");

Similar Messages

  • Launching Java Application From A Java Application

    Hello,
    I am building a compiler and would like to have run feature. The problem is I can not seem to figure out the righ syntax to run and application from my java application.
    Here is the code I am using to run an application:
    public void RunClass()
    try
    Runtime rtr=Runtime.getRuntime();
    Process pr = rtr.exec("java " + CurrentDirectory + FileNoExt);
    String line;
    BufferedReader rerr = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    if((line = rerr.readLine()) == null) { CompileMessageArea.setText("Program Running\n"); }
    while ((line = rerr.readLine()) != null) { CompileMessageArea.append(line +"\n"); }
    rerr.close();
    catch(Exception re) { re.printStackTrace(); }
    The following is an example of what the above would send to the:
    java c:\MyJava\Programs\test
    If you try to type something like that in a DOS prompt it will not work. You must first change to that directory, but I am hoping there is an easy way to change the syntax. On the other hand if you want to compile a program you can type:
    javac c:\MyJava\Programs\test.java
    and it will work just fine. This is kind of funny and I use this syntax for my compiler in my program. You would think that the same syntax would work the same for both compiling and running but it does not. So, I know that if I just know what the correct syntax that dos would except for running an application it would work.
    So, if you have the answer for me PLEASE LET ME KNOW.
    It is easily testable by keying it into the dos prompt.
    Sincerely,
    Eric Kohr

    If you want to do it that way you need to use the environment parameter of the exec() method. Use it to set your classpath to the directory that's need for the java application you are about to run... for instance.
    String[] env = new String[] {"CLASSPATH=c:\classes"}
    String command = "java somePackage.someProgram";
    Runtime.getRuntime().exec( env, command);Where your program is in the file "c:\classes\somePackage\someProgram"
    your mileage may vary :)
    You can also reflectively load classes into the running VM and invoke their main methods. This give you the ablility to control them a bit more.

  • Executing a perl script from within java application

    Hi,
    Does anyone knows a way to execute a perl script from within java.
    ---kirk

    Runtime.exec("perl myscript.pl");
    Of course whether that "works" depends on what the script does and where the java program runs.

  • Opening a java application from a java application

    I am trying to write a simple patching application for a program I am writing. The application must work on both Windows and Mac computers. The program is compiled into a single jar file. To patch the program, I'd like to see if an update is available, download the update if it's available and if the user requests it, and then apply the patch. Since this is a very simple, relatively small program, the "patch" is actually just a newer version of the jar file.
    I've haven't had any problems in detecting or downloading the updated jar file. The problem I'm having is that I can't overwrite the old jar file with the new one while the program is running (of course). Therefore, I wrote a separate patch program that does the actual downloading and replacing work. The order of operations should look like this:
    Open program -> Check for patch -> If user wants to patch then...
    Open patch application -> Close program -> Patch application downloads new jar file and replaces old jar file -> Open original program -> Close patch application.
    However, I can't seem to open the patch application from the original application. I'm using Runtime.getRuntime().exec("java -jar patchApp.jar") but I'm not getting any output whatsoever, neither the program running nor an exception. Can anyone suggest something here? Any help is appreciated.

    However, I can't seem to open the patch application
    from the original application. I'm using
    Runtime.getRuntime().exec("java -jar patchApp.jar")
    but I'm not getting any output whatsoever, neither the
    program running nor an exception. Can anyone suggest
    something here? Any help is appreciated.I've had bad results using the Runtime.exec method. It doesn't seem to be very reliable, at least not in Windows (that's probably not Java's fault.)
    Can you run java by just typing java at the console or do it have to be qualified. Make sure your patchApp.jar argument is in the correct case also.
    I gave up on exec and use JNI to delegate this task to native code. That's going to a little more complicated if you are running in two environemts.

  • Launching a java application from another java application

    Hi,
    I'm facing an interesting challenge :-)
    Inside a Java application, I want to start another java application.
    Possible solutions in my list :
    1. Using jakarta commons launcher.
    2. Runtime.exec (make the code platform dependent).
    3. Starting the main method of the other app by create a new Thread inside the current app
    4. I know people did this by calling an ant target from the java application but I don't have
    any sample code, I appreciate any sample code for it.
    Thanks,
    Ali Salehi

    That is an iteresting challenge :)Don't be mean; he's polite, done some investigation and taken the trouble to be clear. The question, presumably, is "has anyone got a different solution or a preference as to which of these is the best?"
    In which case, my advice would be to say that invoking main in a separate thread is fundamentally different from Runtime.exec() because the former would run in the same JVM. Is this what you want? If one app has the other on its classpath then do they need to be separate apps? Could they be modules of a single app?

  • How can I communicate with other applications from my Java application?

    Hello,
    I need help about how can i communicate with other application(say textpad.exe/wordpad.exe/MS word.exe) from my Java program.
    More precisely, I need to know how i can get the current position of the cursor whether it is in any .txt/.doc files, then I may write some text in my java application and click a button and then my program will append the line(string) in that position of the file which is running under another appliction(Notepade.exe/MSword.exe).
    Please provide me some help.

    I may be wrong (and anyone, please correct me if so), but Java may not be the best tool for something such as this. I envision that you'd have to make some OS calls such as calls to the user32.dll, and while this can be done through the JNI, you'd still have to have a C or C++ program doing the dirty work.

  • Running a java application from a java application

    hello ,
    please who knows how i can run a java application 'B' from inside another java application 'A' and get the error messages (if any) from the application 'B'

    how are you executing application B from application A? Please explain the java code you are using?

  • Launching various external applications from a java application

    I have several java.io.File objects displayed in my swing application. When the user double clicks any of these objects, I want to launch the external application associated with the file type.
    For eg. if the user double clicks on "one.pdf", I want to launch Adobe Acrobat to view that file. I dont want to hard code application and file extension associations, rather I want to launch whatever it is that the underlying OS would launch given a double click on a certain file type.
    Anshuman Taneja.

    Let me answer my own question. Did not know the solution would be this direct. On the flip side, this is not a cross platform solution, and perhaps, there isnt any cross platform solution.
    (in the code below, file is a java.io.File object.)
    // if the file is an "exe", then it is launched like this
    if(file.getName().indexOf(".exe") > 0 )
    Runtime.getRuntime().exec("rundll32" + " " +
    "url.dll,FileProtocolHandler" + " " + file.getName());
    // for files which are not applications themselves,
    // this will launch the application windows would've launched to open the file
    else
    Runtime.getRuntime().exec(new String[]
    {"rundll32", "url.dll,FileProtocolHandler",
    "file:///" + file.getAbsoluteFile()});

  • Running a dos command from a java application

    hello,
    I'm trying to execute a batch file from a java application. I tried with:
    try
    Process proc=Runtime.getRuntime().exec("fop -fo "+iXmlFoFile+" -
    svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                               the Xml FO file into Svg file: "+e);}
    and with:
    try
    Process proc=Runtime.getRuntime().exec("cmd ./c fop
    -fo "+iXmlFoFile+" -svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                the Xml FO file into Svg file: "+e);}
    but i have a IOException: CreateProcess: .... error=2
    When I try these line to launch a .exe file it works but not with a .bat file.
    I also tried:
    String execstr = "fop -fo "+iXmlFoFile+" -svg "+SvgFileName;
    String [] commandArray = { execstr };
    try {
    Runtime.getRuntime().exec(commandArray);
    } // end try
    catch ( Exception e ) {
    System.out.println( e.getMessage() );
    e.printStackTrace();
    }// end catch
    but i got the same exception in java.lang.Win32Process.create
    What did i do wrong?

    Your execution string is a bit more that I want to figure out, but here are a couple ideas:
    Is the working directory of any importance? If so you'll need to set that when you do your exec()
    I think I remember reading something about batch files that couldn't be kicked off via this method. Perhaps you need to execute the string "start mybatchfile.bat". Seems like you need to do something like that to get a command interpreter to run your batch file.

  • How to call pdf forms developed in ABAP from WD Java application?

    Hi
    I have a web dynpro ABAP application that that is responsible for generating PDF forms for all other applications (WD ABAP and WD Java).
    How can I call the pdf forms generated by the WD ABAP application from WD Java application in a separate window?
    These forms are to be called on click of a "Print" button. Also, these forms are non interactive.
    Kindly let me know if you need any other information.
    Regards
    Vineet Vikram
    Edited by: vineet vikram on Jun 24, 2009 7:28 AM

    in addtion to Nikhil's response. you can write following code on action of print button:
        IWDWindow window = wdComponentAPI.
            getWindowManager().createExternalWindow(
                  "<ABAP Application URL>",
                  "<Title for window>",
                  false);
       window.open();
    to Close the application, you can use the window close or u can fire an event to close current window.
    Abhinav

  • Execute a script in a Linux machine from a Java application

    Hi,
    I am trying to execute a script in a Linux machine from a Java application on a Windows environment. My code is
    commande="rsh 185.30.30.30 -l goku /newfolder/bench/bin/Agent start ";
    try{
    Process process = Runtime.getRuntime().exec(commande);
    catch(Throwable t){}
    It works fine but the script takes too much time to start (almost 3 minutes). My question is there exists anther way to execute the script, another command? I have already tried ssh but windows doesn�t recognize it
    If somebody has any idea please let me know...
    Thanks

    The script starts and stops a process (Agent) so it doesn�t take too much time to execute itself. It is when I execute the script from my java program that i must wait to watch my process running in my Linux server.

  • Can we execute DOS Commands from a Java Application

    I just want to know whether we can execute DOS Commands from a Java Application.
    Thanks.

    hi,
    try this:
    Runtime.getRuntime().exec("cmd /c start abc.bat");
    andi

  • Launching TextEdit on a Mac from a Java application

    I am having a problem launching textedit from a Java application. It was working a week ago on a fresh iMac, but since then I have installed Lightroom, Photoshop, the Studio MX suite stuff, and now the textedit program does not start from my Java app. This is the code that I am using in my application to launch textedit:
    String command = "open -e \""+filename.getAbsolutePath()+"\"";
    Runtime rt = Runtime.getRuntime();
    rt.exec(command);I've also tried it this way:
    String command = "open -e \""+filename.getAbsolutePath()+"\"";
    Process child = Runtime.getRuntime ().exec (command);I've printed the command to execute out on the console and it appeared like this:
    open -ef "\Users\user\Desktop\filename.txt"But it doesn't open textedit. The funny thing is, if I copy and paste that open command into the Terminal, it will open the file in TextEdit. Why won't it work in my Java app anymore, but still work through the terminal? I don't get any errors in the console, it just doesn't open TextEdit anymore. Is there a setting somewhere that might have been changed that let me start TextEdit from a Java app. I checked and TextEdit is still my default program for opening text files, which I guess makes since why it works from the Terminal, but I don't get why it doesn't start TextEdit from my Java app.
    Some of this might just be a Mac issue, I'm new to that system. But the code I'm using used to work. I guess maybe I'm looking for another (better) way of opening TextEdit on the Mac from Java.
    I'm using Java 1.5.0_07. Thanks.

    Try specifying an absolute path for open (/usr/bin/open ?).

  • How can i call a VB6 project from my java application using JNI

    hi
    can anyone tell me the procedure of calling a VB6 project from any java application using JNI
    if anyone does know then tell me the detail procedure of doing that. I know that i have to create a dll of that VB6 project then to call it from the java application.
    if anyone know that procedure of creating dll file of an existing VB6 project please reply
    please if anyone know then let me know

    Ahh, kind of a duplicate thread:
    http://forums.java.sun.com/thread.jspa?threadID=631642
    @OP. You could have clarified your original post and the relationship of your question to java. You did not need a new thread.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How do i Hyperlink to a web page from a java application?

    How do i Hyperlink to a web page from a java application using internet explorer as my default web browser?

    It's very simple.You can start any Application with the class Runtime. The command is an array consisting of the path of .exe and the file to be open.
    String [] cmd={path of IE+Filename.exe,"URL of your website"}
    try
    Runtime.getRuntime().exec(cmd);
    catch (Exception e)
    System.err.println(e.toString());
    }

Maybe you are looking for

  • GenericSortFilter not applying propery on some of the columns

    Hi Gurus I am trying to apply GenericSortFilter action block on the below xml documnet. I can successfully apply on last column but not first two columns . <?xml version="1.0" encoding="UTF-8"?> <Rowsets DateCreated="" EndDate="" StartDate="" Version

  • CD burn problem

    I am trying to burn a dvd. When I insert it into the supported drive, I get a prompt and I select the Finder option for opening it. No when I drag or copy the required the files into this finder of the dvd, it pastes the shortcut of those files. I ha

  • Change the default language in AM

    Hello, We are using Lookups in our application which stores the locale specific information. We have a drop down in the UI which will give the language names like 'American English', 'Canadian French' etc. When chosen 'Canadian French' we need to cha

  • Assignment of Standard Purchase Organization to Site

    Hi I am working on Creation of Auto PO while making GR in 501 mvt type in IS-Retail ECC 6.0 . I want to assign the Standard Pur Org to site in assignment . I am unable to see the sites which are created in with reference to reference site in WB01. Pl

  • *** Serialization in SOAP ***

    Hi, I m building a web service with Jdeveloper 9.0.3 . I m trying to pass org.w3c.dom.Document in the function argument but got the following error: No Serializer found to serialize a 'org.w3c.dom.DOMImplementation' using encoding style 'http://schem