0

我正在使用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 上

4

2 回答 2

0

例如 Enigmail 使用的第三方“ipc”库允许您捕获命令的输出。它甚至可能在某个时候成为 XULrunner 的一部分。

编辑:正如评论中所讨论的,nsIProcess.run 使用 exec 而不是 system 所以脚本需要有一个 #! 行,以便内核可以生成 shell。

于 2011-03-06T00:21:04.797 回答
0

从上面的讨论中,听起来这个过程可能根本没有开始。

我会尝试两件事

  • 尝试调用其他一些进程/可执行文件
  • 将null更改为[],也许它默默地失败了,期望这是一个数组(即使它是一个空数组)
于 2011-03-10T18:48:05.123 回答