Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation running a programme from another in Java

    Im having lots of problems it would seem but my latest one (and hopfully my last) is this,

    I have my min programme running but i need to call and runn another program (which also has its own main method), but i cant seem to get it to work.

    any ideas?

    Kusky

  • #2
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if it is a class and in the same folder as the class you are doing try this

    classname.main();
    such as the class you are running is bob it would be
    bob.main();
    but bob must be in the same folder you have the first one in

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Read up on the Runtime object. You can get a reference to it using getRuntime(), and use this reference to run external programs by using Runtime.exec().
    Think of this as being able to use a shell within a program.
    For example:

    Runtime r = Runtime.getRuntime();
    Process p = r.exec("java yournewprogram");
    //now you have a process running yournewprogram

    There are a few other details you may want to work out, read up on it.

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i have tried to use the Runtime object but when i compile is says

    Runtime() has private access in java.lang.Runtime

    i have read up on Runtime but i really dont know whats wrong!

    Please help

  • #5
    New Coder
    Join Date
    Feb 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please post the code in which you are trying to get and use the aforementioned Runtime object.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •