mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 18:42:27 +01:00
improve error reporting when running shell commands with :!
This commit is contained in:
@@ -522,46 +522,56 @@ lookup:
|
|||||||
|
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
|
// XXX
|
||||||
liberator.echoerr("Command not found: " + program);
|
liberator.echoerr("Command not found: " + program);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var process = Components.classes["@mozilla.org/process/util;1"].
|
var process = Components.classes["@mozilla.org/process/util;1"].
|
||||||
createInstance(Components.interfaces.nsIProcess);
|
createInstance(Components.interfaces.nsIProcess);
|
||||||
process.init(file);
|
|
||||||
|
|
||||||
var ec = process.run(blocking, args, args.length);
|
process.init(file);
|
||||||
return ec;
|
process.run(blocking, args, args.length);
|
||||||
|
|
||||||
|
return process.exitValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
|
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
|
||||||
// is fixed, should use that instead of a tmpfile
|
// is fixed, should use that instead of a tmpfile
|
||||||
system: function (str, input)
|
system: function (str, input)
|
||||||
{
|
{
|
||||||
var fileout = ioManager.createTempFile();
|
var stdoutFile = ioManager.createTempFile();
|
||||||
if (!fileout)
|
var stderrFile = ioManager.createTempFile();
|
||||||
|
|
||||||
|
if (!stdoutFile || !stderrFile) // FIXME: error reporting
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
var command = str + " > " + fileout.path;
|
var command = str + " > " + stdoutFile.path + " 2> " + stderrFile.path;
|
||||||
else
|
else
|
||||||
var command = str + " > \"" + fileout.path.replace('"', '\\"') + "\"";
|
var command = str + " > \"" + stdoutFile.path.replace('"', '\\"') + "\"" + " 2> \"" + stderrFile.path.replace('"', '\\"') + "\"";
|
||||||
|
|
||||||
|
var stdinFile = null;
|
||||||
|
|
||||||
var filein = null;
|
|
||||||
if (input)
|
if (input)
|
||||||
{
|
{
|
||||||
filein = ioManager.createTempFile();
|
stdinFile = ioManager.createTempFile(); // FIXME: no returned file?
|
||||||
ioManager.writeFile(filein, input);
|
ioManager.writeFile(stdinFile, input);
|
||||||
command += " < \"" + filein.path.replace('"', '\\"') + "\"";
|
command += " < \"" + stdinFile.path.replace('"', '\\"') + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: why is this return value being ignored?
|
|
||||||
var res = ioManager.run(liberator.options["shell"], [liberator.options["shellcmdflag"], command], true);
|
var res = ioManager.run(liberator.options["shell"], [liberator.options["shellcmdflag"], command], true);
|
||||||
|
|
||||||
var output = ioManager.readFile(fileout);
|
if (res > 0)
|
||||||
fileout.remove(false);
|
var output = ioManager.readFile(stderrFile) + "\nshell returned " + res;
|
||||||
if (filein)
|
else
|
||||||
filein.remove(false);
|
var output = ioManager.readFile(stdoutFile);
|
||||||
|
|
||||||
|
stdoutFile.remove(false);
|
||||||
|
stderrFile.remove(false);
|
||||||
|
|
||||||
|
if (stdinFile)
|
||||||
|
stdinFile.remove(false);
|
||||||
|
|
||||||
// if there is only one \n at the end, chop it off
|
// if there is only one \n at the end, chop it off
|
||||||
if (output && output.indexOf("\n") == output.length - 1)
|
if (output && output.indexOf("\n") == output.length - 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user