Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Opening and operating programs in java on a mac

  1. Jan 26, 2011 #1
    I started taking a java course at my school and we are required to use macs. I looked for how to open other programs like text edit or the terminal but the code segments I found only worked for java. Is it possible to have a java program open other programs like text edit or the terminal on a mac? And if so how?
  2. jcsd
  3. Jan 26, 2011 #2
    I'm not entirely sure what you're asking here. You mean you want to launch some external program from Java code?

    If so, the Runtime class has exec functions that can do that:


    There's so many ways of doing it. And exec isn't always the best way, but it might be what you're looking for.

    I found a page with a rather large number of different ways to run external programs from Java:


    Not sure why you want to do that in this case, but that's up to you. :smile:
  4. Jan 26, 2011 #3
    ok, thanks. I got a little farther but everytime I run it I get an error saying permission denied. Do you know how to get around this? Also some of the terms used on the site confused me so I kinda had to guess. Here is what I wrote, maybe I just wrote something wrong.

    Process p = new ProcessBuilder("/Applications/Skype.app", "myArg").start();
  5. Jan 26, 2011 #4
    Keep in mind that the "myArg" means you're passing the application an argument of "myArg". That was just a placeholder in the example in the docs. Unless you're trying to pass that as a parameter (don't see why), you can just remove it.

    As for the permission problem, I'm not entirely sure. I assume you caught an IOException? I would guess that it's your operating system and not the Java Virtual Machine (but I could be wrong). As for how to fix it, I'm not totally sure. Someone who knows Macs will have to chime in here. There's probably some way of giving the application permission to launch Skype, but I personally have no clue how to do it on a Mac and would be reaching.
  6. Jan 26, 2011 #5
    Alright, thanks a lot.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Opening and operating programs in java on a mac
  1. Java programs (Replies: 9)

  2. Java Programming (Replies: 12)