Results 1 to 4 of 4
  1. #1
    JBird is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default Run external programs using runtime class

    Okay, I'm experiencing a really annoying problem with java.lang.runtime

    I'm building a GUI that needs to run some external programs, via a button say. These generally produce a text file or something, so I don't need to stream the output or anything (at least I'm assuming I don't?). Should be very simple...

    So at the terminal (bash) I would type ./programName , and everything will run hunkey dorey.

    In my code then, natrurally, I write

    String cmd = "./programName";
    Process p = runtime.getRuntime().exec(cmd);

    But low and behold...nothing happens. What is going on here, and how do I get around it! ??

    (On windows incidentally, it's no problem at all and works absolutely fine. But when I go over to mac, which is what I need to use, I'm screwed - only adding to the annoyance!)

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Could we see a little more of your code? I'm on a mac, and the runtime runs apps just fine for me.

  3. #3
    JBird is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    Sure thing..

    private void buttonExeActionPerformed(java.awt.event.ActionEven t evt) {

    try{

    String cmd = "./plotTest";
    Process pr = Runtime.getRuntime().exec(cmd);

    } catch(Exception ex){}
    }

    Any clues??

    I can access some apps by passing String[] cmd = {"open", "appName"}; to exec(), so why doesn't it work when I'm using ./appName to run them ??

    Any help will be much appreciated, I have a deadline hanging horribly over me!

    thanks

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    This works fine for me:
    Java Code:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    /**
     * @author Steffen Gates
     */
    public class NativeProcess {
        public static void main(String[] args) {
            new NativeProcess();
        }
    
        public NativeProcess(){
            try {
                Process p = Runtime.getRuntime().exec("date");
                BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                System.out.println(reader.readLine());
            } catch (IOException ex) {
                Logger.getLogger(NativeProcess.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    Are you sure the native app you are trying to execute is in the right PATH?
    Last edited by quad64bit; 08-06-2009 at 03:41 AM.

Similar Threads

  1. Replies: 3
    Last Post: 04-02-2009, 09:16 PM
  2. External runtime resources access in Eclipse
    By batkins61 in forum Eclipse
    Replies: 0
    Last Post: 01-07-2009, 06:42 PM
  3. Replies: 1
    Last Post: 11-14-2008, 07:56 AM
  4. executing external programs
    By Levish2002 in forum AWT / Swing
    Replies: 0
    Last Post: 09-10-2008, 08:04 PM
  5. Using Runtime to execute external commands
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-05-2008, 10:14 AM

Posting Permissions

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