what is the equivalent method to call a cmd command in Java? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

what is the equivalent method to call a cmd command in Java?

for example, in c++ it's system("a command"); after including <cstdlib>. also in python after importing subprocess it's, subprocess.call(["cmd.exe","a command here"]) does anyone know how to call it in Java?

29th Jan 2018, 1:32 PM
Hayyan Jarboue
Hayyan Jarboue - avatar
2 Respostas
+ 2
You can use "Runtime.getRuntime().exec()", which returns a Process object. You can also use the ProcessBuilder: "Process p = new ProcessBuilder("Command", "Arg", " arg2").start();"
29th Jan 2018, 1:54 PM
Moritz Vogel
Moritz Vogel - avatar
+ 1
thank you so much Moritz i'll try it now
29th Jan 2018, 1:57 PM
Hayyan Jarboue
Hayyan Jarboue - avatar