diff --git a/lib/shell.js b/lib/shell.js index 2a37013..a82a0b9 100644 --- a/lib/shell.js +++ b/lib/shell.js @@ -73,23 +73,32 @@ var ShellObject = function() { } }; - this.exec = function(cmd, stdOutPath) { - var data; + 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); - if (typeof(stdOutPath) === "undefined") { - stdOutPath = "stdout.txt"; - } var c = "%comspec% /c (" + this.build(cmd) + ") 1> " + stdOutPath; - c += " 2>&1"; + //c += " 2>&1"; + c += " 2> " + stdErrPath; this.interface.Run(c, 0, true); console.info("ShellObject.exec() -> " + c); - data = FILE.readFile(stdOutPath, "utf-8"); - - if (FILE.fileExists(stdOutPath)) { - FILE.deleteFile(stdOutPath); - } + sleep(1); - return data; + if (FILE.fileExists(stdOutPath)) { + stdout = FILE.readFile(stdOutPath, "utf-8"); + FILE.deleteFile(stdOutPath); + } + + if (FILE.fileExists(stdErrPath)) { + stderr = FILE.readFile(stdErrPath, "utf-8"); + FILE.deleteFile(stdErrPath); + } + + //console.log("[stdout] " + stdout); + //console.log("[stderr] " + stderr); + + return stdout; }; this.run = function(cmd, fork) {