Home > Web Front-end > JS Tutorial > body text

How to execute cmd command in JAVAscript

藏色散人
Release: 2021-07-02 12:02:31
Original
15473 people have browsed it

The method for JAVAscript to execute cmd command: first open the corresponding code file; then execute the CMD command function through "function JsExecCmd(value) {...}".

How to execute cmd command in JAVAscript

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;
}
Copy after login

Reference:

function run() {
var command = "echo lance  shuai  i love  !" //这里是执行的DOS命令
JsExecCmd(command );
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!