Issues while using Runtime exec() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Issues while using Runtime exec()

Hey everyone! I've just learned to use the Runtime.getRuntime().exec() command, and it executed aĺl the files and cmd commands i've tested. But when i tryed to execute a prompt command to execute a java class, it didn't do anything. I used the following line of code: //After compiling the java code try { Runtime.getRuntime().exec("cmd /c java " + className); } catch(Exception e) {} If you see an error, i'll be thankful if you tell me.

5th Jul 2017, 4:01 AM
Silas Junior
Silas Junior - avatar
4 Answers
+ 1
wow Sorry i cant help you,what i did in the cmd was simple
23rd Jul 2017, 4:00 PM
Gabrielle Cristine
Gabrielle Cristine - avatar
+ 1
No problem. God bless you
23rd Jul 2017, 4:02 PM
Silas Junior
Silas Junior - avatar
0
Tell me ALL that you've did in the cmd
23rd Jul 2017, 10:34 AM
Gabrielle Cristine
Gabrielle Cristine - avatar
0
First i wrote a java file using Scanner. Then i used the following command in order to compile the file: Runtime.getRuntime().exec("cmd /c javac " + dir + fileName + ".java"); After compiling, i should execute the generated class. Here's the commands: Runtime.getRuntime().exec ("cmd /c java " + dir + className); And that's the part when the command seems to fail, and nothing happens, not even an error message. The same problem happens when i try to execute or create a .jar file: Executing: Runtime.getRuntime().exec("cmd /c java -jar " + fileName + ".jar"); Creating: Runtime.getRuntime().exec("cmd /c jar cvfm " + fileName + ".jar" + manifest + " " + className + ".class");
23rd Jul 2017, 3:50 PM
Silas Junior
Silas Junior - avatar