문제

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?

도움이 되었습니까?

해결책 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!

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top