1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 15:48:00 +01:00

Uglily fix io.system with multibyte commands.

This commit is contained in:
Kris Maglione
2008-12-17 18:58:07 -05:00
parent 304bfab29e
commit ec26e68027

View File

@@ -720,48 +720,38 @@ lookup:
function escape(str) '"' + str.replace(/[\\"$]/g, "\\$&") + '"'; function escape(str) '"' + str.replace(/[\\"$]/g, "\\$&") + '"';
let stdoutFile = ioManager.createTempFile(); return this.withTempFiles(function (stdin, stdout, stderr, cmd) {
let stderrFile = ioManager.createTempFile();
if (!stdoutFile || !stderrFile) // FIXME: error reporting
return "";
if (WINDOWS)
{
command = "cd /D " + cwd.path + " && " + command + " > " + stdoutFile.path + " 2> " + stderrFile.path;
}
else
{
let cmd = util.Array.flatten([options["shell"], options["shellcmdflag"].split(/\s+/), command]).map(escape).join(" ");
command = "cd " + escape(cwd.path) + " && exec " + cmd + " >" + escape(stdoutFile.path) + " 2>" + escape(stderrFile.path);
}
let stdinFile = null;
if (input) if (input)
{ {
stdinFile = ioManager.createTempFile(); // FIXME: no returned file? this.writeFile(stdin, input);
ioManager.writeFile(stdinFile, input); command += " <" + escape(stdin.path);
command += " <" + escape(stdinFile.path);
} }
let res = ioManager.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true); if (WINDOWS)
{
if (res > 0) command = "cd /D " + cwd.path + " && " + command + " > " + stdout.path + " 2> " + stderr.path;
var output = ioManager.readFile(stderrFile) + "\nshell returned " + res; var res = this.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true);
}
else else
var output = ioManager.readFile(stdoutFile); {
this.writeFile(cmd, Array.concat("exec", options["shell"], options["shellcmdflag"].split(/\s+/), command).map(escape).join(" "));
command = "cd " + escape(cwd.path) + ' && eval "$(cat <' + escape(cmd.path) + ')" >' + escape(stdout.path) + " 2>" + escape(stderr.path);
liberator.dump("command: " + command);
res = this.run("/bin/sh", ["-c", command], true);
}
stdoutFile.remove(false); if (res > 0) // FIXME: Is this really right? Shouldn't we always show both?
stderrFile.remove(false); var output = ioManager.readFile(stderr) + "\nshell returned " + res;
if (stdinFile) else
stdinFile.remove(false); output = ioManager.readFile(stdout);
// 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)
output = output.substr(0, output.length - 1); output = output.substr(0, output.length - 1);
return output; return output;
}) || "";
}, },
// FIXME: multiple paths? // FIXME: multiple paths?
@@ -950,6 +940,21 @@ lookup:
{ {
ioManager.sourcing = wasSourcing; ioManager.sourcing = wasSourcing;
} }
},
withTempFiles: function (fn, self)
{
let args = util.map(util.range(0, fn.length), this.createTempFile);
if (!args.every(util.identity))
return false;
try
{
return fn.apply(self || this, args);
}
finally
{
args.forEach(function (f) f.remove(false));
}
} }
}; //}}} }; //}}}