我正在运行一个脚本nsIProcess.run(),我发现获得输出的唯一方法是将输出写入文件,然后从JavaScript中读取文件。在Xulrunner中获取脚本输出(shell脚本)的最佳方式是什么?
但由于某些原因,当我从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);
}
my-script.sh:
echo ok > /tmp/result.txt
有没有更好的(和工作)的方式来得到my-script.sh这个 “OK” 输出?
--update
我在Ubuntu 10.04使用的XULrunner 1.9.2.15
尝试在您的shell脚本中使用绝对路径。它的当前目录可能不是你想象的那样。 – 2011-03-04 16:40:02
那么脚本是否被执行,但是文件没有被写入,或者脚本没有被执行?可以确认它确实以某种方式运行? – pc1oad1etter 2011-03-04 17:57:29
@丹尼斯威廉姆森好点。不幸的是,它仍然没有创建文件。 – 2011-03-04 18:01:03