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 ?
- stackoverflow.com/questions/23650193/…Ele– Ele2017-12-12 21:09:47 +00:00Commented Dec 12, 2017 at 21:09
Add a comment |
1 Answer
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
2 Comments
pawan bhatt
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
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.