WSH/JScriptでコマンド実行の方法をメモ
var shell = new ActiveXObject("WScript.Shell");
shell.Exec("notepad"); // コマンドを実行
あるいは、ウィンドウの状態などを指定したい場合:
var shell = new ActiveXObject("WScript.Shell");
shell.Run("notepad"); // コマンドを実行
終了まで待機する場合
var shell = new ActiveXObject("WScript.Shell");
var e = shell.Exec(cmd); // コマンドを実行
while (e.Status == 0) {
WScript.Sleep(100);
}
コマンドの戻り値(標準出力)を得る場合
function runCommand(cmd_str) {
var shell = new ActiveXObject("WScript.Shell");
// コマンドを実行
var oe = shell.Exec(cmd_str);
var r = oe.StdOut.ReadAll();
return r;
}