1

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 ?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I want to run a python script from the same and pass parameter to it through args, so how can i do that ????
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.