Launch many java programs at runtime

Hi i got one question.
i have a list of java program ina file.
i read this file and get each program names.
i would like to launch all java programs at Runtime from my main Java application.
here is my code so far:
String fileName = expansion + ".txt";
          try
               File file = new File(fileName);
               FileReader     fileReader= new FileReader(file);
               BufferedReader bufferReader = new BufferedReader(fileReader);
               while((program=bufferReader.readLine())!= null)
                    Runtime launch=Runtime.getRuntime();
                    System.out.println("I launch "+ program);
                    launch.exec("cmd.exe /c start /c cd /bin");
                    launch.exec("java "+program);
this does not work. How can i handle this?
thank you
seb

while((program==bufferReader.readLine())
!= null) {Sorry, I meant
while((program==bufferReader.readLine())!= null) {{=^)                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Launching a Java Program from UNIX ( C/C++ )

    How do I launch my Java program from c/c++? Do I need to wrap my java command line ( ie. java -classpath .... ) in a C shell ? Is there another way?

    How do I launch my Java program from c/c++? Do I need
    to wrap my java command line ( ie. java -classpath
    .... ) in a C shell ? Is there another way?You can do it directly using Java Native Interface (JNI). Using this approach the Java program runs in the current process.
    Sylvia.

  • Execute an external java program with Runtime, problem with classpath

    Hi,
    I m calling an external java program by the command:
    Runtime.getRuntime().exec("java -classpath \"library/*\" org.mypackage.TestMainProgram param1 c:/input/files c:/output/files");All my classes are stored in the relative directory "library", and it contains ONLY .jar files. However, I keep getting errors like:
    "java.lang.NoClassDefFoundError: library/antlr/jarCaused by: java.lang.ClassNotFoundException: library.antlr.jar     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)Could not find the main class: library/antlr.jar. Program will exit.Exception in thread "main" where "antlr.jar" is a jar file in "library". It is there but still the program keeps complaining it cannot be found. The problem applies to any jars in "library", ie.., if i have "mylib.jar" then it will complain "NoClassDefFoundError: library/mylib/jar".
    Could anyone give some pointers please?
    Many thanks!
    Edited by: 836590 on 14-Feb-2011 09:03

    836590 wrote:
    Hi,
    I m calling an external java program by the command:
    Runtime.getRuntime().exec("java -classpath \"library/*\" org.mypackage.TestMainProgram param1 c:/input/files c:/output/files");All my classes are stored in the relative directory "library", and it contains ONLY .jar files. However, I keep getting errors like:
    "java.lang.NoClassDefFoundError: library/antlr/jarCaused by: java.lang.ClassNotFoundException: library.antlr.jar     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)Could not find the main class: library/antlr.jar. Program will exit.Exception in thread "main" where "antlr.jar" is a jar file in "library". It is there but still the program keeps complaining it cannot be found. The problem applies to any jars in "library", ie.., if i have "mylib.jar" then it will complain "NoClassDefFoundError: library/mylib/jar".
    Could anyone give some pointers please?
    Many thanks!
    Edited by: 836590 on 14-Feb-2011 09:03First, if you run from the command line
    java -classpath "library/*" org.mypackage.TestMainProgram param1 c:/input/files c:/output/filesfrom the parent directory of library, does it work?
    Despite what I said to Kayaman about Runtime.exec not expanding the asterisk, it looks like that's what's happening, so that you're getting
    java -claspath library/aaaa_something_before_antlr.jar library/antlr.jar library/bbb.jar library/ccc.jar  org.mypackage.TestMainProgram param1 c:/input/files c:/output/filesThat is, it *is* expanding the asterisk to a list of files in the directory, and the first one is being taken as the classpath, and the second one--library/antlr.jar is being taken as the class to execute. I'm certain this doesn't happen on Linux, so it must be a Windows thing.
    Two suggestions:
    1) Try single quotes instead of double.
    2) Try the exec that takes an array
    Runtime.getRuntime().exec(new String[] {"java", "-classpath", "'library/*'", "org.mypackage.TestMainProgram", "param1", "c:/input/files", "c:/output/files");Edited by: jverd on Feb 14, 2011 9:41 AM

  • How to launch a java program in a new process

    Hello !
    II have a Java program, in which I want to carry out another Java program but in a new process, this new program requiring the definition of constants to the launching of the JVM.
    How can I do it ?
    Tank you for your help.

    Use
    Runtime.getRuntime().exec( cmd ); //where cmd is command for run java program.
    cmd may be "java test".
    You may also try using jnlp to run you java program in a new process.
    cmd will be "cmd /c \"javaws " + jnlpFile + "\"";

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • How can i launch another java application using Runtime class?

    I created a java process which invokes another java application called Launch as shown below,
    Process p=Runtime.getRuntime().exec("java -classpath=C:\\Program Files\\bin\\nettools\\ui\\updates Launch");
    But it is not working...can any one help me on this?
    Edited by: deepakchandaran on Sep 20, 2007 7:10 AM

    You could search the forum and Google.
    it has been answered before.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Launch a java program in a specific tty

    Hello,
    I'm writing a popup program (with Swing) which has to launch popup in every tty where a user is logged in.
    I succeeded to get the list of tty where my user is logged in but i don't know how to show my popup (JOptionPane.showMessageDialog(...)) in these.
    Thanks for all.
    Mik

    a virtual terminal in Unix OS

  • Cannot launch (many) Java 3D Applications on Leopard

    I have tried a number of different Java applets (http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/repositoryApplets.ht ml) that use Java 3D and run into the same launch error each time:
    java.lang.UnsupportedClassVersionError: javax/media/j3d/ImageComponent (Unsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:1655)
    at java.lang.Class.getMethod0(Class.java:1901)
    at java.lang.Class.getMethod(Class.java:984)
    at com.sun.javaws.Launcher.executeApplication(Launcher.java:1312)
    at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1270)
    at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1117)
    at com.sun.javaws.Launcher.run(Launcher.java:105)
    at java.lang.Thread.run(Thread.java:552)
    My suspicion is that I accidentally installed bad/outdated Java3D jar files in
    System/Library/Java/Extensions.
    I've tried every Java update I could find, including JavaForMacOSX10.5Update2, and keep running into the same launch error. Any ideas?

    Try using 'Applications/Utilities/Java/Java Preferences' to change the default Java version.

  • Calling a Java Program from another

    Hi,
    I am putting together a Java program which will launch other Java programs.
    I was thinking of doing this by calling unix scripts from my java program by getting an instance of the Runtime object and then calling the exec method with the script name.
    I am just wondering what is the best practice when doing this? i.e., dealing with timeout issues, and errors in the scripts etc.
    I have read this article, which is quite good: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
    Is there any code available on the web that deals with all of the basic error scenarios?
    Is it good practice to use a java program to call another java program? Or is there a better way of doing this?
    The main reason I am using java is because I am most familiar with it and I need to connect to a database as well and do some manipulation of results returned.
    Any thoughts or suggestions would be much appreciated.
    Message was edited by:
    LondonJavaDev

    Thanks Prometheuzz
    Is the main difference between your suggestion and
    using the Runtime.getRuntime().exec(cmd) way of doing
    things is that in the former both eill run as the
    same process (Thread) but in the second scenario the
    .getRuntime().exec(cmd) will start a separate new
    thread?
    Many ThanksCorrect. But you can create a sort of wrapper class for A which implements Runnable and stuff it in it's own thread. If you're dealing with Java code only, I advise you to create threads yourself instead of letting your OS handle them.
    Here's a demo:
    class Foo {
        public static void main(String[] args) {
            (new Thread(new ARunner())).start();
            B.main(null);
    class ARunner implements Runnable {
        public void run() {
            A.main(null);
    class A {
        public static void main(String[] args) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) { /* ... */ }
            System.out.println("A");
    class B {
        public static void main(String[] args) {
            System.out.println("B");
    }Of course, you can create a wrapper for B as well.

  • How to launch a java application from Microsoft SQL Server

    Hi everyone
    I noticed the following line in a trigger will launch an executable.
    EXEC master..xp_cmdshell '"C:\Program Files\SkillSets.exe"', NO_OUTPUT
    Does anyone know if this same statement will launch a java program? Or does anyone have any positive experience with that ?

    yes...
    check this basic example:
    public class GoodWindowsExec{
    public static void main(String args[]){
    if (args.length < 1){
    System.out.println("USAGE: java GoodWindowsExec <cmd>");
    System.exit(1);
    try{           
    String osName = System.getProperty("os.name" );
    String[] cmd = new String[3];
    if( osName.equals( "Windows NT" ) ){
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    }else if( osName.equals( "Windows 95" ) ){
    cmd[0] = "command.com" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1]
    + " " + cmd[2]);
    Process proc = rt.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 (Throwable t)
    t.printStackTrace();

  • Running a java program at "Start Up"

    Besides running an html file with an applet in it. Are there any simple ways to launch a java program every time the computer is turned on.
    I am not asking for specific directions, but rather just an idea, and i will go find my own guide.

    Well two ideas (if ur on windows) u could try are -
    one, if you had a class file you could simply create a
    batch file on windows that says java <class> and then
    put that batch file in your startup so that the class
    is run at startup or else you could think of modifying
    the registry keys on windows to run this class at
    startup - whichever works for you.Or you could just jar the program up, adding a Main-Class indicator in the manifest, and then add a shortcut to the jar to the startup folder, as someone else stated. Theres little need to go messing around with DOS batch in modern windows.

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • URGENT:- Running a batch file from java program

    Author: pkanury
    I am trying to execute a batch file from my java program using RunTime and Process . It can execute any dos command except for a batch file. Can anyone throw
    some light ?? My code looks like this .....
    cmd = "command.com /c X:\\grits\\scripts\\test.bat"; Runtime rt = Runtime.getRuntime(); Process p = rt.exec(cmd);
    The weird part is that p.waitFor() returns a status of 0 implying that the cmd has been executed successfully. But that is not the case. And my batch file is as simple as - type "ADADA" > junk.txt
    Any help would be appreciated.

    I think it should work when you use a String[] array
    instead of a single String:
    String[] cmd = { "command.com", "/C", "D:\\batch\\do.bat" };
    Note: If the batchfile creates any output (i.e. files),
    they will be stored in the directory of the application
    which calls the batch file, not in d:\batch\...

  • Start a java program from an FMB then read and write some variables

    Hello,
    I am trying to see whether the following setup works:
    item A, B, D and Button Z are on a Forms Canvas.
    User clicks on Button Z. This will launch a java program (Myprog class).
    Myprog main will read values in item A and B, run some calculation and then will return it back to our forms module and then will be displayed in item D.
    I have read about PL/SQL wrapper but the way I am looking at my setup is that my Forms module will be just the GUI interface.
    Any ideas ?

    main thing: a JAVA class that will take some inputs and will output some results and messages.
    Prob: I do not want to use swing or any other GUI builder to make a nice GUI for my JAVA class.
    What I want: I know how to use Forms. As such, I just want to put together a quick interface (mymodule.fmb) that when executed will allow the user to click on a button to start the java process and then see the results and error messages.
    Why I don't want to go through SWING: my main prob is to get the java class executed ( which is fine right now thru command line) by other users thru a GUI interface. I do not have time to go thru SWING.
    From the paper I mentioned, I think the PJC is the way to go. Can you please confirm ?
    Thanks.

  • Executing C program in a Java Program

    How can I execute a C program in a JAVA program!

    Runtime.getRuntime().exec("yourProgramName.exe");
    Or maybe you wann use JNI (Java Native Interface) if you want interaction between the C program and the Java program...

Maybe you are looking for