welsonjs/lib/shell.js

36 lines
965 B
JavaScript
Raw Normal View History

2020-07-07 09:02:51 +00:00
////////////////////////////////////////////////////////////////////////
// Shell API
////////////////////////////////////////////////////////////////////////
2020-07-21 09:01:38 +00:00
var FILE = require("lib/file");
2020-07-07 09:02:51 +00:00
exports.VERSIONINFO = "Shell Module (shell.js) version 0.1";
exports.global = global;
exports.require = global.require;
2020-07-07 09:02:51 +00:00
exports.exec = function(cmd, stdOutPath) {
2020-07-07 17:06:38 +00:00
var WSH = CreateObject("WScript.Shell"),
2020-07-07 09:02:51 +00:00
data;
if (typeof(stdOutPath) == "undefined") {
stdOutPath = "stdout.txt";
}
var c = "%comspec% /c (" + cmd + ") 1> " + stdOutPath;
c += " 2>&1";
2020-07-07 17:06:38 +00:00
WSH.Run(c, 0, true);
2020-07-07 09:02:51 +00:00
data = FILE.readFile(stdOutPath, "utf-8");
if (FILE.fileExists(stdOutPath)) {
FILE.deleteFile(stdOutPath);
}
return data;
}
exports.run = function(cmd, fork) {
2020-07-07 17:06:38 +00:00
var WSH = CreateObject("WScript.Shell");
2020-07-07 09:02:51 +00:00
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c " + cmd;
2020-07-23 10:38:19 +00:00
WSH.Run(c, 0, !fork);
2020-07-07 09:02:51 +00:00
};