Reputation: 3593
I want to open my cmd.exe by a click on a Button and with a String path that I give to my cmd.exe as a parameter (open the cmd with that path set)
String path = getCurrentFolderName().toString();
ProcessBuilder b = new ProcessBuilder();
b.environment().put("PATH", path);
b.command("cmd", "/c", "start", path)
b.start();
this so far opens only the folder in a new window in Windows... how can I open my cmd.exe and pass a path to it?
Upvotes: 0
Views: 960
Reputation: 23
In the past when I need to do something like this I would create and delete batch files. Use PrintWriter to create your .bat file, you can add in whatever variables you need at this point
Then to run the .bat
Runtime.getRuntime().exec("cmd /c start build.bat");
and delete it afterwords if its not needed.
Maybe not elegant, but it worked well for me before.
Upvotes: 0
Reputation: 159844
Few changes necessary
ProcessBuilder#directory
/k
flag to maintain CMD shellpath
argumentResult
ProcessBuilder b = new ProcessBuilder();
b.directory(new File(path));
b.command("cmd", "/k", "start");
Upvotes: 1