Calling Java program in another Java program

Discussion in 'Java' started by Rey, Dec 12, 2003.

  1. Rey

    Rey Guest

    Hi,
    I have a Java program which requires it to make a another java
    program and use the result it produces. I am working on a very limited
    knowledge of java and i don't know how i can achieve it, I will
    appreciate any one who can send me an example

    Tks
    -spirit
     
    Rey, Dec 12, 2003
    #1
    1. Advertising

  2. Rey wrote:
    > I have a Java program which requires it to make a another java
    > program and use the result it produces. I am working on a very limited
    > knowledge of java and i don't know how i can achieve it, I will
    > appreciate any one who can send me an example


    There are two methods: use java.lang.Runtime.exec() or (preferably) call
    the main() method of the other program's main class. However, if the program
    works with standard in and out, you need to change System.in and System.out.
     
    Michael Borgwardt, Dec 12, 2003
    #2
    1. Advertising

  3. "Michael Borgwardt" <> wrote in message
    news:brcuer$1uoqh$-berlin.de...
    > Rey wrote:
    > > I have a Java program which requires it to make a another java
    > > program and use the result it produces. I am working on a very limited
    > > knowledge of java and i don't know how i can achieve it, I will
    > > appreciate any one who can send me an example

    >
    > There are two methods: use java.lang.Runtime.exec() or (preferably) call
    > the main() method of the other program's main class. However, if the

    program
    > works with standard in and out, you need to change System.in and

    System.out.

    I am not sure the OP understands, so I will add..

    Java is OO. You do not necessarily need to call
    the 'main()' as Michael said, to get data from another
    Java package (program or application).

    If you can import classes from the other
    package and instantiate them, you may never
    need to call a main() method of the other
    package.

    I guess you did not write the other Java program..
    Do you have the source of the other program?
    Or do you have access to the JavaDocs?

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
     
    Andrew Thompson, Dec 12, 2003
    #3
  4. Michael Borgwardt <> writes:

    > There are two methods: use java.lang.Runtime.exec() or (preferably) call
    > the main() method of the other program's main class. However, if the program
    > works with standard in and out, you need to change System.in and System.out.


    Though you will also want to install a SecurityManager to trap any
    System.exit() calls from that other app.
     
    Tor Iver Wilhelmsen, Dec 12, 2003
    #4
  5. Rey

    Roedy Green Guest

    On 12 Dec 2003 09:33:59 -0800, (Rey) wrote or
    quoted :

    > I have a Java program which requires it to make a another java
    >program and use the result it produces. I am working on a very limited
    >knowledge of java and i don't know how i can achieve it, I will
    >appreciate any one who can send me an example


    You can just call the main method of the other program e.g.

    Other.main(someparms);

    You can use exec. See http://mindprod.com/jgloss/exec.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Dec 12, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    514
    Andrew Thompson
    Oct 31, 2005
  2. Yann Laviolette

    Linux - Getdate question and calling another program

    Yann Laviolette, Nov 2, 2003, in forum: C Programming
    Replies:
    3
    Views:
    494
    Yann Laviolette
    Nov 2, 2003
  3. joshivaibhav
    Replies:
    3
    Views:
    638
    joshivaibhav
    Nov 21, 2006
  4. utab
    Replies:
    18
    Views:
    1,661
    Diego Martins
    Apr 27, 2006
  5. Silveira Neto

    Calling a another program from Java

    Silveira Neto, Sep 21, 2007, in forum: Java
    Replies:
    3
    Views:
    405
    Joshua Cranmer
    Sep 22, 2007
Loading...

Share This Page