1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-22 05:55:46 +01:00

minor refactoring of io.system() - add escapeQuotes()

This commit is contained in:
Doug Kearns
2008-09-23 02:40:12 +00:00
parent 398f93f5e1
commit ed327496ff

View File

@@ -654,7 +654,6 @@ lookup:
if (!file.exists()) if (!file.exists())
{ {
// XXX
liberator.echoerr("Command not found: " + program); liberator.echoerr("Command not found: " + program);
return -1; return -1;
} }
@@ -675,13 +674,16 @@ lookup:
var stdoutFile = ioManager.createTempFile(); var stdoutFile = ioManager.createTempFile();
var stderrFile = ioManager.createTempFile(); var stderrFile = ioManager.createTempFile();
function escapeQuotes(str) str.replace('"', '\\"');
if (!stdoutFile || !stderrFile) // FIXME: error reporting if (!stdoutFile || !stderrFile) // FIXME: error reporting
return ""; return "";
if (WINDOWS) if (WINDOWS)
var command = str + " > " + stdoutFile.path + " 2> " + stderrFile.path; var command = str + " > " + stdoutFile.path + " 2> " + stderrFile.path;
else else
var command = str + " > \"" + stdoutFile.path.replace('"', '\\"') + "\"" + " 2> \"" + stderrFile.path.replace('"', '\\"') + "\""; var command = str + " > \"" + escapeQuotes(stdoutFile.path) + "\""
+ " 2> \"" + escapeQuotes(stderrFile.path) + "\"";
var stdinFile = null; var stdinFile = null;
@@ -689,7 +691,7 @@ lookup:
{ {
stdinFile = ioManager.createTempFile(); // FIXME: no returned file? stdinFile = ioManager.createTempFile(); // FIXME: no returned file?
ioManager.writeFile(stdinFile, input); ioManager.writeFile(stdinFile, input);
command += " < \"" + stdinFile.path.replace('"', '\\"') + "\""; command += " < \"" + escapeQuotes(stdinFile.path) + "\"";
} }
var res = ioManager.run(liberator.options["shell"], [liberator.options["shellcmdflag"], command], true); var res = ioManager.run(liberator.options["shell"], [liberator.options["shellcmdflag"], command], true);