Java Opening and operating programs in java on a mac

Click For Summary
A user in a Java course on Mac seeks guidance on launching external programs like TextEdit or Terminal from Java code. The discussion highlights that the Java Runtime class can execute external applications using the exec functions. A specific code example using ProcessBuilder to open Skype is provided, but the user encounters a "permission denied" error when attempting to run it. Clarification is given that "myArg" is a placeholder for an argument, which can be removed if not needed. The cause of the permission issue is uncertain, with suggestions that it may relate to macOS settings rather than Java itself, prompting the need for further assistance from someone knowledgeable about Mac permissions.
Yoyo_Guru
Messages
32
Reaction score
0
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?
 
Technology news on Phys.org
Yoyo_Guru said:
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?

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:

http://download.oracle.com/javase/6/docs/api/index.html

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:

http://www.rgagnon.com/javadetails/java-0014.html

Not sure why you want to do that in this case, but that's up to you. :smile:
 
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();
 
Yoyo_Guru said:
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();
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.
 
Alright, thanks a lot.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
Replies
1
Views
2K
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
19
Views
4K
  • · Replies 15 ·
Replies
15
Views
3K