Update shell.js

This commit is contained in:
Namhyeon Go 2021-08-11 16:29:49 +09:00 committed by GitHub
parent 8841b2f255
commit 6c62891397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ var ShellObject = function() {
this.interface = CreateObject("WScript.Shell");
this.currentDirectory = this.interface.CurrentDirectory;
} catch (e) {
console.error("ShellObject.create() -> " + e.message);
console.error("ShellObject.create() ->", e.message);
}
return this;
};
@ -36,7 +36,7 @@ var ShellObject = function() {
if (typeof(dirname) === "string") {
this.workingDirectory = dirname;
this.interface.CurrentDirectory = this.workingDirectory;
console.info("ShellObject.workingDirectory -> " + this.workingDirectory);
console.info("ShellObject.workingDirectory ->", this.workingDirectory);
}
return this;
};
@ -66,23 +66,24 @@ var ShellObject = function() {
this.createProcess = function(cmd) {
try {
var c = this.build(cmd);
console.info("ShellObject.createProcess() -> " + c);
console.info("ShellObject.createProcess() ->", c);
return this.interface.Exec(c);
} catch (e) {
console.error("ShellObject.createProcess() -> " + e.message);
console.error("ShellObject.createProcess() ->", e.message);
}
};
this.exec = function(cmd, stdOutPath, stdErrPath) {
var stdout, stderr;
var stdOutPath = (typeof(stdOutPath) === "undefined" ? "stdout.txt" : stdOutPath);
var stdErrPath = (typeof(stdErrPath) === "undefined" ? "stderr.txt" : stdErrPath);
var seed = parseInt(Math.random() * 10000);
var stdOutPath = (typeof(stdOutPath) === "undefined" ? "tmp\\stdout_" + seed + ".txt" : stdOutPath);
var stdErrPath = (typeof(stdErrPath) === "undefined" ? "tmp\\stderr_" + seed + ".txt" : stdErrPath);
var c = "%comspec% /c (" + this.build(cmd) + ") 1> " + stdOutPath;
//c += " 2>&1";
c += " 2> " + stdErrPath;
this.interface.Run(c, 0, true);
console.info("ShellObject.exec() -> " + c);
console.info("ShellObject.exec() ->", c);
sleep(1);
if (FILE.fileExists(stdOutPath)) {
@ -104,14 +105,14 @@ var ShellObject = function() {
this.run = function(cmd, fork) {
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c (" + this.build(cmd) + ")";
console.info("ShellObject.run() -> " + c);
console.info("ShellObject.run() ->", c);
this.interface.Run(c, (!this.isVisibleWindow ? 0 : 1), !fork);
};
this.runAs = function(FN, args) {
var oShell = CreateObject("Shell.Application");
var _args = null;
console.info("ShellObject.runAs() -> " + FN);
console.info("ShellObject.runAs() ->", FN);
if (typeof(args) !== "undefined") {
_args = args.join(' ');
}
@ -143,7 +144,7 @@ var ShellObject = function() {
};
this.release = function() {
console.info("ShellObject.release() -> " + this.currentDirectory);
console.info("ShellObject.release() ->", this.currentDirectory);
this.interface.CurrentDirectory = this.currentDirectory;
this.interface = null;
};