什么';在Xulrunner中获取脚本(shell脚本)输出的最佳方法是什么?
我正在用运行一个脚本,我发现获取输出的唯一方法是将输出写入一个文件,然后从javascript读取该文件 但由于某些原因,当我从xulrunner应用程序执行它时,它不会生成带有输出的文件。以下是我的功能:什么';在Xulrunner中获取脚本(shell脚本)输出的最佳方法是什么?,shell,xul,xulrunner,Shell,Xul,Xulrunner,我正在用运行一个脚本,我发现获取输出的唯一方法是将输出写入一个文件,然后从javascript读取该文件 但由于某些原因,当我从xulrunner应用程序执行它时,它不会生成带有输出的文件。以下是我的功能: function runProcess() { // create an nsILocalFile for the executable var file = Components.classes["@mozilla.org/file/local;1"].createInst
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获得“ok”输出
--更新
我使用的是Ubuntu10.04和Xulrunner 1.9.2.15,有一个第三方的“ipc”库,例如Enigmail,它允许您捕获命令的输出。它甚至可能在某个时候成为XULrunner的一部分
编辑:如注释中所述,nsIProcess.run使用exec而不是system,因此脚本需要有一个#!这样内核就可以生成shell了。从上面的讨论来看,这个过程似乎根本没有启动 我会尝试两件事
- 尝试调用其他进程/可执行文件
- 将null更改为[],可能是静默失败,希望这是一个数组(即使它是一个空数组)
#/bin/bash
line解决了这个问题。谢谢我已经为[]
更改了null
,但没有任何更改。我不确定是否通过调用process.init(“firefox”)
本来应该启动firefox,但也没有发生任何事情。通过调用其他.sh
文件也无法工作。