Sometimes we need to use the Java program to open some of the computer's own programs, you can open directly or with the CMD Command window to open some of the commonly used applications. For example:
Packagecn.xm.exam.test;Importjava.io.IOException;Importorg.junit.Test; Public classtestCMD {@Test Public voidTest1 ()throwsIOException {//Open the application directlyRuntime.getruntime (). EXEC ("c:/users/liqiang/desktop/dot it after booting. bat");//open a batch fileRuntime.getruntime (). EXEC ("e:/cool Dog/kgmusic/kugou.exe");//turn on the cool dog /******** can open the software with the cmd command or do other * * * **/runtime.getruntime (). EXEC ("C:/windows/system32/cmd.exe/k start e:/Cool dog/kgmusic/kugou.exe");//executing commands from the cmd windowRuntime.getruntime (). EXEC ("c:/windows/system32/cmd.exe/k start e:/php/test/First html/interface. html");//open a Web page with the cmd commandRuntime.getruntime (). EXEC ("c:/windows/system32/cmd.exe/k mkdir C:\\users\\liqiang\\desktop\\java key 1");//Create a directory with CMD with two backslashesRuntime.getruntime (). EXEC ("c:/windows/system32/cmd.exe/k mkdir C:\\users\\liqiang\\desktop\\java key 2");//Create a directory with CMD with two backslashesRuntime.getruntime (). EXEC ("c:/windows/system32/cmd.exe/c calc");//Open calculator with cmd} @Test Public voidTest2 ()throwsIOException {/******** can open the software with the cmd command or do other * * * **/runtime.getruntime (). EXEC ("C:/windows/system32/cmd.exe/c Osk");//Through the on- screen soft keyboard }}
Call Cmd when the middle of the/C and/k is the CM parameter, Windows view parameter description:
C:\users\liqiang>cmd/?start a new instance of the Windows command interpreter CMD [/A | /u] [/q] [/d] [/e:on |/e:off] [/f:on |/f:off] [/V:ON |/V:off] [[/S] [/C |/K] [string]/C executes the string specified by the command and then terminates/K executes the command specified by the string but retains/S Modify/C or/string processing after K (see below)/Q Turn off Echo/D prohibit execution of the AutoRun command from the registry (see below)/a makes the internal command output to the pipe or file an ANSI/U make the internal command output to a pipe or file Unicode/T:FG set the foreground/background color (For more information, see Color/?).)/e:on Enable command Extensions (see below)/e:off Disabling command extensions (see below)/f:on enable file and directory name completion characters (see below)/f:off disable file and directory name completion characters (see below)/v:on use!enables deferred environment variable extension as a delimiter. For example,/v:on will allow!var!the variable var is extended at execution time. The var syntax expands the variable as it is entered, unlike in a For loop. /V:off Disables the deferred environment extension. Note that if the string is enclosed in quotation marks, you can accept the command delimiter"&&"separate multiple commands. In addition, due to compatibility reasons,/x is the same as/e:on,/y is the same as/e:off, and/R and/C is the same. Any other switches will be ignored. If you specify a/C or/K, the remainder of the command line after the switch is processed as a command line, where the quotation marks are processed using the following logic (") Character: 1. The quote character on the command line is preserved if all of the following conditions are true:-Not with/S Switch-exactly two quote characters
Java open Local application (call cmd)