I am using following code to open cmd in windows and execute the cd command and its working fine for me.
Process p = Runtime.getRuntime().exec("cmd /c \" cd C:\\Users"");
I want to do the same in mac by opening console, so what should i write instead of cmd ?
Asked
Active
Viewed 3,201 times
1

pawan bhatt
- 15
- 1
- 6
-
https://stackoverflow.com/questions/23650193/how-to-open-terminal-and-execute-command-using-java-code-in-osx – Ele Dec 12 '17 at 21:09
1 Answers
0
You need to run it using bash
executable like this:
String[] args = new String[] {"/bin/bash", "-c", "your_command", "with", "args"};
Process proc = new ProcessBuilder(args).start();
Follow this link: https://stackoverflow.com/a/15356451/1715121

Ele
- 33,468
- 7
- 37
- 75
-
I want to run a python script from the same and pass parameter to it through args, so how can i do that ???? – pawan bhatt Dec 14 '17 at 19:13
-
String para="here is parameter to python script"; cmd="cd /users/downloads/ && python myScript.py" ; String []args ={ "bin/bash" , "-c" , cmd , para }; its not working. – pawan bhatt Dec 14 '17 at 19:41