Question

I try to run an exe file from cmd that I open by Java, but nothing happens. The cmd that oppened seems like:

C:\>file.exe
C:\>

When I open manually cmd the exe file runs. the cmd seems the same in both cases! (manually and via Java). My code is:

File projDir = new File("C:/");
String command = "cmd /c start file.exe";
Process p = Runtime.getRuntime().exec(command, null, projDir);

Do you have an idea?

Was it helpful?

Solution 2

Thank you all for your help, I found a parallel way to run the exe file, and this way works:

List<String> args = new ArrayList<String>();
args.add("path\\of\\exe\\file");
ProcessBuilder pb = new ProcessBuilder(args);
pb.start();

anyway - thanks for trying to help me!

OTHER TIPS

You dont need run an exe thru cmd. This should be enough:

Runtime.getRuntime().exec("file.exe", null, projDir);

and thru cmd with:

Runtime.getRuntime().exec(new String[]{"cmd","/c","start file.exe"}, null, projDir);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top