How to run java programs from a master java program?

Hello,
I have several java programs which run from the command prompt. I am seeking help with code for starting java programs from within a java program. For example, a program called master.java works something like this:
import java.*;
create connection pool
create variables and result sets
start/run slave1.java (var1, var2);
start/run slave2.java (var3, var4, var5);
start/run slave3.java (var1, var4);
end of program master.java
Each of the slave.java programs will run for up to an hour. I do not want the master.java program to pause for each slave program to stop. Instead, the master program will keep running and multiple slave programs will be running simultaneously with the master program. When a slave program starts, it is on its own. Also, if possible, I would like to have each of these slave.java programs open in a new separate command window, so I can observe each slave program running in separate windows.
Any suggestions for code or helpful documentation are greatly appreciated.
Thank you,
Logan

Thank you all.
At the bottom of master.java I have successfully started a batch file with these lines:
String jcmd = "cmd.exe /c start c:/data/simulations/MsgViewCount2.bat";
Process proc = Runtime.getRuntime().exec(jcmd);
But I still cannot get a java program to start. Here is one variation I have tried:
String [] cmdArray = new String[2];
cmdArray[0] = "java";
cmdArray[1] = "slave1";
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmdArray);
This compiles, and no errors occur, but nothing happens.
Regarding this comment:
Why Runtime.exec? Either make the slaves Runnable or
just call their main() methods.
Oh, I see. Sepearate output. :PNone of the slave.java programs have any output.
Thanks again.

Similar Messages

  • How do you run another Java file from a master Java file?

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!One doesn't "run a Java file", and there's no conventional definition of "master Java file". If you want to call the main() method of another class, just make sure the class is in your classpath and call the method. If you want to start up a separate JVM with that class as a process, use Runtime.exec() or similar method.
    ~

  • How to run an exe file in a java program

    Hi,
    Can somebody tell me how to run an exe file in a java program.
    Thank you!

    Yes, java.lang.Runtime.exec().
    Read this carefully before you do:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Don't write a line of code before you're reviewed and understood the article completely. - MOD

  • How to execute a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
    And finally, how do I execute that Perl program from within the Java program.
    If I execute the Perl program alone then I do it in the following way -
    perl abc inp1 inp2 inp3
    where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.

    what part of don't crosspost, don't you understand?
    http://forum.java.sun.com/thread.jsp?forum=4&thread=427193

  • Executing a Java Program from within a Java Program

    I need to execute the following Java Program from withing another Java Program. The office toolbar command line is
    D:\WINDOWS\system32\java.exe -cp E:\Development\Eclipse\UpdateServer\Classes -server -showversion UpdateServer
    I can find no combination of ProcessBuilder commands, including those that include "Cmd.exe /c" that will make this program run from within another Java Program. All the examples I can find only show how to run Windows *.exe programs. I keep getting error 123 from ProcessBuilder.start(), but I can find no documentation for error 123.

    Assuming your code didn't get mangled by the forum
    (it's missing one "), it may be that your "-cp
    E:\\Develop.." argument is getting quoted as it has a
    space in it; try passing "-cp" and "E:\\Develop..."
    as two arguments.That worked; specifically the following tested OK:
    ProcessBuilder pb = new ProcessBuilder("D:\\WINDOWS\\System32\\Java.exe", "-cp", "E:\\Development\\Eclipse\\UpdateServer\\Classes\\", "-server", "-showversion", "UpdateServer" );
    pb.directory(new File("E:\\Development\\Eclipse\\UpdateServer\\Classes\\"));
    try{
         Process p = pb.start();
         InputStream is = p.getErrorStream();
         InputStreamReader isr = new InputStreamReader(is);
         BufferedReader br = new BufferedReader(isr);
         String line;
         while ((line = br.readLine()) != null)
              System.out.println(line);
         p.waitFor();
    }catch(IOException ioe){
    I was sure I tried that exact same code before, and it did not work, but now it does, at least at the top level (when it is in main of a test program). I will have to wait to try it until later when it is buried deep in a subroutine.

  • Executing C program from with a java program

    How do you call a c program from within a java program, and parse arguments into that program and return something.
    Cheers for any reply...

    Read http://www.javaworld.com/jw-12-2000/jw-1229-traps.html

  • Executing a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say that the Perl program that I want to execute is 'abc'.'abc' requires some input that I want to give from within the java program. How do I do that? Then I want to execute the Perl program from within the Java prog. How do I do it?

    don't crosspost.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=427211&tstart=0&trange=100

  • How to run a report from oracle 10g form in .csv format

    dear all,
    how to run a report from oracle 10g form in .csv format? i've already run in pdf & excel format.
    i'm using
    SET_REPORT_OBJECT_PROPERTY (ro_report_id, report_desformat, 'PDF'); --for pdf
    SET_REPORT_OBJECT_PROPERTY (ro_report_id, report_desformat, 'SPREADSHEET'); ---for excel
    Please Help..

    i have already tried.
    but the report show in htm or html format. that file will not save into csv. please help.

  • How to run ZAC CDP from a Linux Bundle

    Hi all,
    I am trying to work out how to run "ZAC CDP" from a Linux bundle. We have 330 Satelites that I need to force the replication of the TFTP folder too in one staggered process.
    Is there any reason why this would not work? would a script do it and anyone have a sample?
    cheers,
    Trev.

    I would imagine it's possible.
    I'm assuming something (run as root user?)
    #!/bin/bash
    zac cdp
    (you may have to put the absolute path in for the location of "zac")
    I'm not a linux guru by any means, just that if you can script this via a cron job, I'm sure it can be done via ZCM Bundle.

  • How to run db.xml from ORPOS 13.4 version on standalone

    Hi All,
    How to run db.xml from ORPOS 13.4, We dont have ORBO.
    Thanks & Regards
    GM

    Go to the location where your installer is residing and execute the following command:
    install.cmd ant install-database
    Regards,
    Uttam Kumar

  • How to run batch file from oracle forms 9i

    Hi everyone.
    i have a data in csv file. i want to upload it to my database. i am using sql loader for it.
    i have made a batch file which run the sql loader and transfer my data to database.
    How to run batch file from oracle forms 9i.
    when i press the button, nothing uploads in my database. (when i simply run the batch file it works).
    here is my code
    Begin
    HOST('C:\temp\batchfile.bat');
    message('done');
    end;
    Thanks in advance
    regards
    sajid

    this is my log file, when i run manually.
    SQL*Loader: Release 10.2.0.1.0 - Production on Thu Jul 1 23:27:53 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Control File: file_to_upload.ctl
    There are 2 data files:
    Data File: sk.csv
    Bad File: sk.bad
    Discard File: none specified
    (Allow all discards)
    Data File: sk1.csv
    Bad File: sk1.bad
    Discard File: none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table KHAN, loaded from every logical record.
    Insert option in effect for this table: APPEND
    Column Name Position Len Term Encl Datatype
    SR FIRST * , O(") CHARACTER
    DATES NEXT * , O(") CHARACTER
    AGENT NEXT * , O(") CHARACTER
    COUNTRY NEXT * , O(") CHARACTER
    TRANSACTIONS NEXT * , O(") CHARACTER
    PKR NEXT * , O(") CHARACTER
    USD NEXT * , O(") CHARACTER
    BANK NEXT * , O(") CHARACTER
    Table KHAN:
    11088 Rows successfully loaded.
    0 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 132096 bytes(64 rows)
    Read buffer bytes: 1048576
    Total logical records skipped: 0
    Total logical records read: 11088
    Total logical records rejected: 0
    Total logical records discarded: 0
    Run began on Thu Jul 01 23:27:53 2010
    Run ended on Thu Jul 01 23:27:54 2010
    Elapsed time was: 00:00:00.63
    CPU time was: 00:00:00.17

  • How do I convert pics from old Adobe Photoshop program on cd in pdd to jpeg?

    I have cds with pdd pics from my old (1999) Adobe Photoshop program.  My system won't open them.  I now have Photoshop Elements 8.  I can go to Organize and get photos from the cd.  They are in my catalog and I can open them there.
    How do I convert them to jpeg?
    When I go to Edit, I can't find my photos in the catalog.  I only find the new pics in my Photo Gallery that are already jpeg.
    I feel as though I'm missing something simple.  Can someone help me?

    Thanks for your response.  I did get a way to do it with the software I already have.
    Date: Thu, 27 May 2010 00:15:37 -0600
    From: [email protected]
    To: [email protected]
    Subject: How do I convert pics from old Adobe Photoshop program on cd in pdd to jpeg?
    There's a utility called "Image Converter Plus" that can do this for you.  They modestly calls it "the best image converter in the industry.  You can see their web site at:  http://www.imageconverterplus.com/help-center/work-with-icp/examples/how-to-convert/PDD_jp g.html .
    Here's from their web site:
    h1. How to convert PDD to JPG
    Converting PDD to JPG is very easy with Image Converter Plus. In Windows Explorer, select a PDD image and click your right mouse button. In the context menu, select Convert to submenu and click Custom convert line.
    ==========
    This seems to be exactly what you want.
    Since they have a separate "download" and "purchase" section, it's not clear to me if you have to pay the $49 license fee to use the utility.  You may have to purchase the license to get batch processing. 
    Even if you do have to pay, my philosophy in life is that if someone can rescue some important pictures with their $49 utility, then it's worth the price.
    >

  • How do run my library from an external drive?

    How do run my library from an external drive? I've tried changing destination locations but nothing seems to work. help please

    You might find this article useful, there's a section in it on moving to an external drive:
    iLounge - Transferring your iTunes Library to Another Drive

  • How to terminate and restart a java program from a controling java program?

    I have a situation where my program needs to run exactly once each one
    hour. This is a huge program that creates a lot of threads and opens
    lot of resources. After one hour has lapsed, I want to terminate this
    program (as if Exit(0) was performed on it or as if Ctrl C was pressed
    from the command line to terminate a running program) and then run it again and so on repeat the cycle each hour. This will guarantee that
    all the resouces taken by the programs are freed or if some threads were still blocked on i/o, are indeed terminated each hour.
    The java program does not have any user interface and it is run from the
    command line.

    if you can change the program to be controlled, you could make it listen for commands on some networkport for shutting it down.
    If this is not an option you could start OS programs to kill the first program. On Unix System kill will do, but you need the process id so you'd need another os call ...
    You could do the os calls in two ways
    a) execute shell commands (search the forum on how to do that
    b) write a little C wrapper for the os call so you can call them from JNI (Java Native Interface)
    I do not know of any way do this kind of thing directly
    regards
    Spieler

  • How to start a browser from within a java program?

    I want to make a help file for my java program and want to run the browser from the menu of my program.
    How can I start my browser from my program?
    A small code will be helpful.
    Thanks.
    Niteen

    This should work on Windows without having to know where the browser is located. See http://www.javaworld.com/javaworld/javatips/jw-javatip66.html for more details
      public static void viewHtml(URL url, boolean fixHtmlExtension){
          String cmd = "rundll32 url.dll,FileProtocolHandler " + url.toExternalForm();
          if (fixHtmlExtension){
            //There is a bug in rundll32. For http requests, it doesn't like .html or .htm extensions,
            //but replacing the 'm' with '%6D' works. 
            //This fix is not needed for file requests.
            if (cmd.endsWith(".htm")){
              cmd = cmd.substring(0,cmd.length()-1) + "%6D";
            else if (cmd.endsWith(".html")){
              cmd = cmd.substring(0,cmd.length()-2) + "%6Dl";
          Process process = Runtime.getRuntime().exec(cmd);
          try{
            process.waitFor();
          catch(InterruptedException e){

Maybe you are looking for

  • How to get full playlist to play

    I just installed my Apple TV. I immediately wanted to simply play a playlist from my iTunes library. I selected the playlist I wanted, and pressed play on the remote. It played ONLY the first song, then stopped. In order to hear any other songs I had

  • Lightroom moving difficulties from external to other external drives.

    Okay, well here goes. I guess i don't fully understand how Lightroom 5 uses the pictures and a separate cat properly. I set up lightroom 5 on a Laptop (Macbook pro)and used it for about 3 years so i have 2012 2103 and 2014 folders inside. After watch

  • How to have iTunes library on macbookpro show up on iPad and iPhone 5

    My itunes library on my macbook pro doesn't show on my Ipad and Iphone 5. How can I do that? Also, what I purchase on my iphone in itune store doesn't show up on my library on my macbook pro.

  • Need help regarding HR

    Hi All,   Am working on HR-ABAP and am planning to learn the HR(Functional side) . could any one help me by sending useful materials ? My id is [email protected] Thanks & Regards Anil

  • InfoPackage - system table

    Hi Experts, Do you know anybody the name of the systems (SAP) tables for InfoPackage ? i need to obtain info about InfoPackage, DataSource and "Select DataTargets" Thanks a lot in advance Martin