Reputation: 3
I'm trying to compile and execute a .java file, using a java program.
Runtime.getRuntime().exec("cmd.exe /c start javac myProg.java");
Runtime.getRuntime().exec("cmd.exe /c start java myProg");
The file compiles and i think it runs as well but then it exits. I need to keep the cmd window open.
I tried using \k
instead of \c
and using pause
. They don't seem to work. What am i doing wrong? Thanks in advance :D
Upvotes: 0
Views: 2151
Reputation: 5329
Make these changes in your code and it will work. You need to add option /k
as shown below.
Runtime.getRuntime().exec("cmd /c start cmd /k javac myProg.java");
Runtime.getRuntime().exec("cmd /c start cmd /k java myProg");
Upvotes: 2