What is the difference between Runtime.getRuntime (). Exec () and double click to execute batch file?

What is the difference between Runtime.getRuntime (). exec () and double click to execute batch file?

when I execute a batch file using Runtime.getRuntime (). exec () (case 1) like this,

String[] command = {"cmd.exe", "/C", "Start", "D:\\test.bat"};
Process p =  Runtime.getRuntime().exec(command);  

or

Process p = Runtime.getRuntime().exec("cmd /c start "+"D:\\test.bat")

a new cmd console window opens and runs test.bat.

and if I try to execute test.bat with two clicks of the mouse on my desktop (case 2), it also opens in a new cmd console window and launches the application.

but the problem occurs when I try to stop test.bat. I use "Ctrl-C" to stop the batch file,

when I use “Ctrl-C” in case 1, the cmd console stops, but the window string and tooltips remain.

"Ctrl-C" 2, cmd !

1. , .. ?

. 'exit' test.bat, .

+4
1

Runtime.exec() java, , cmd . , start ( cmd C , ).

, exit test.bat, ctrl + c script, exit .

, :

cmd /C start cmd /C test.bat
+1

Source: https://habr.com/ru/post/1624200/


All Articles