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 if (input)
return ""; {
this.writeFile(stdin, input);
command += " <" + escape(stdin.path);
}
if (WINDOWS) if (WINDOWS)
{ {
command = "cd /D " + cwd.path + " && " + command + " > " + stdoutFile.path + " 2> " + stderrFile.path; command = "cd /D " + cwd.path + " && " + command + " > " + stdout.path + " 2> " + stderr.path;
} var res = this.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true);
else }
{ 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); 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);
}
let stdinFile = null; if (res > 0) // FIXME: Is this really right? Shouldn't we always show both?
var output = ioManager.readFile(stderr) + "\nshell returned " + res;
else
output = ioManager.readFile(stdout);
if (input) // if there is only one \n at the end, chop it off
{ if (output && output.indexOf("\n") == output.length - 1)
stdinFile = ioManager.createTempFile(); // FIXME: no returned file? output = output.substr(0, output.length - 1);
ioManager.writeFile(stdinFile, input);
command += " <" + escape(stdinFile.path);
}
let res = ioManager.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true); return output;
}) || "";
if (res > 0)
var output = ioManager.readFile(stderrFile) + "\nshell returned " + res;
else
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 (output && output.indexOf("\n") == output.length - 1)
output = output.substr(0, output.length - 1);
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));
}
} }
}; //}}} }; //}}}