The method for JAVAscript to execute cmd command: first open the corresponding code file; then execute the CMD command function through "function JsExecCmd(value) {...}".
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How does JAVAscript execute the cmd command?
js method of executing CMD commands
function JsExecCmd(value) { var cmd = new ActiveXObject("WScript.Shell"); /* 命令参数说明 cmd.exe /c dir 是执行完dir命令后关闭命令窗口。 cmd.exe /k dir 是执行完dir命令后不关闭命令窗口。 cmd.exe /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。 cmd.exe /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。 */ //执行完cmd命令后不关闭命令窗口。 cmd.run("cmd.exe /k "+value); //执行完cmd命令后不关闭命令窗口。 cmd.run("cmd.exe /k "+value); cmd = null; }
Reference:
function run() { var command = "echo lance shuai i love !" //这里是执行的DOS命令 JsExecCmd(command ); }
Recommended study: "javascript Advanced Tutorial 》
The above is the detailed content of How to execute cmd command in JAVAscript. For more information, please follow other related articles on the PHP Chinese website!