Update shell.js

This commit is contained in:
Namhyeon Go 2024-07-10 11:27:02 +09:00 committed by GitHub
parent 3e67209ae8
commit 9dda6f1e09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,18 +16,22 @@ var ShellObject = function() {
this.stdout = null;
this.stderr = null;
this.target = null;
this.create = function() {
try {
this.interface = CreateObject("WScript.Shell");
this.currentDirectory = this.interface.CurrentDirectory;
this.workingDirectory = this.currentDirectory;
this.workingDirectory = this.currentDirectory;
} catch (e) {
console.error("ShellObject.create() ->", e.message);
}
return this;
};
this.setTarget = function(target) {
this.target = target;
};
this.setCharset = function(charset) {
this.charset = charset;
@ -49,10 +53,14 @@ var ShellObject = function() {
};
this.build = function(cmd) {
var wrap = function(s) {
return this.target != null ? [this.target, s].join(' ') : s;
};
if (typeof(cmd) === "string") {
return cmd;
return wrap(cmd);
} else if (typeof(cmd) === "object") {
return cmd.map(function(s) {
return wrap(cmd.map(function(s) {
if (s == '') {
return "''";
} else if (!/[ "=]/g.test(s)) {
@ -60,9 +68,9 @@ var ShellObject = function() {
} else {
return "\"" + addslashes(s) + "\"";
}
}).join(' ');
}).join(' '));
} else {
return "";
return wrap('');
}
};
@ -212,7 +220,7 @@ exports.getPathOfMyDocuments = function() {
exports.CdoCharset = PipeIPC.CdoCharset;
exports.VERSIONINFO = "Shell interface (shell.js) version 0.3.7";
exports.VERSIONINFO = "Shell interface (shell.js) version 0.3.8";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;