0

I have the following code to open a command prompt window Runtime.getRuntime().exec("cmd.exe /c start");, but I'm trying to open the prompt with a different location loaded into it.

The idea behind the program is to allow the user to choose one of 3 options to load the command prompt window into, and they're mounted on different locations for example two of them are X:/myJava/ and H:/publicJava/.

How can I open the command prompt window that is loaded into these folders once the user makes their choice?

asked Oct 22, 2014 at 16:35

3 Answers 3

3

Use this Runtime.getRuntime().exec("cmd.exe /c start", null, new File("X:/myJava"));

answered Oct 22, 2014 at 16:45
Sign up to request clarification or add additional context in comments.

2 Comments

then set this as answer!
I have to wait 2 days
0

You can use making a batch file with commands like x: cd publicJava

and then execute that batch file using the Runtime.getRuntime().exec("myBatch.bat");

answered Oct 22, 2014 at 16:56

Comments

-2

Try this

Runtime.getRuntime().exec("cmd.exe /c start /d d:\\java");

The start command accepts a path via the "/d" switch. Keep in mind that you have to escape the backwards slash in the path, hence the double slash.

answered Oct 22, 2014 at 16:41

2 Comments

I managed to figure it out and got it to work with this Runtime.getRuntime().exec("cmd.exe /c start", null, new File("X:/myJava"));
I updated my answer to include the Java bit. That will work for you without the need to create a File instance. Though it's not that big of a deal.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.