0

我正在尝试从 Java 程序启动 firefox,到目前为止我也知道如何使用选项来做到这一点。但我有兴趣发送一个特定的参数,以便 javascript 插件可以获取它。例如,我使用命令 Runtime.getRuntime().exec("/usr/bin/firefox") 来启动 firefox,我的目标是使用类似 Runtime.getRuntime().exec("/usr/bin/firefox 12345"),其中 12345 是我的论点,并通过一个简单的附加组件获得它。

这可能吗?是否有另一种方法/方式可以将参数传递给 Firefox 启动时的附加组件?

提前致谢。

4

4 回答 4

2

使用包含您的论点的 url 启动 Firefox。

于 2012-01-31T18:22:47.630 回答
1

用它作为Runtime.getRuntime().exec(new String[] {"/usr/bin/firefox", "12345"})

无法告诉您如何在 Firefox 插件中获取该参数。如果这是您主要要问的,也许可以修改您的问题?

于 2012-01-31T18:16:36.160 回答
0

I think your functionality would break the security model of firefox. but there are commands that you can use, http://www.binaryturf.com/lesser-firefox-command-line-options/

于 2012-01-31T18:20:31.613 回答
0

首先感谢大家的回答,大家帮助我完成这项工作。在对一些安全问题进行更多研究和思考之后,我最终使用 Java 进程构建器添加了一个具有我想要的值的环境变量:

    //Initiates the process i'm about to start.
    ProcessBuilder pb = new ProcessBuilder(args);
    //Gets the system environment.
    Map<String, String> env = pb.environment();
    //Register VAR with value Value as an evironment variable in this process context
    env.put("VAR", "Value");
    //Stats the process initiated in the 1st line.
    pb.start();

所以有了这个我可以运行一个应用程序并在它的上下文中拥有环境变量,现在我只想在我的 JavaScript 插件中访问它们,只需这样做:

    var env = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsiEnvironment);
    var X = env.get('VAR');

其中 X 将具有环境变量 VAR 中的值(之前在 Java 代码中定义);

于 2012-02-02T12:48:01.403 回答