我正在使用nsIProcess.run()运行脚本,我发现获取输出的唯一方法是将输出写入文件,然后从 javascript 读取文件。
但是由于某种原因,当我从 xulrunner 应用程序执行它时,它不会生成带有输出的文件。这是我的功能:
function runProcess() {
// create an nsILocalFile for the executable
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces["nsILocalFile"]);
file.initWithPath("/home/me/my-script.sh");
write("FILE EXISTS = " + file.exists()); // it is printing TRUE, good!
// create an nsIProcess
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file);
// Run the process.
// If first param is true, calling thread will be blocked until
// called process terminates.
// Second and third params are used to pass command-line arguments
// to the process.
process.run(true, [], 0);
}
我的脚本.sh:
echo ok > /tmp/result.txt
有没有更好的(和有效的)方法来从 my-script.sh 获得这个“好的”输出?
- 更新
我在带有 Xulrunner 1.9.2.15 的 Ubuntu 10.04 上