如何从命令行优雅地杀死firefox [英] how to kill firefox gracefully from command line

查看:456
本文介绍了如何从命令行优雅地杀死firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要打开URL列表的程序.我在Ubuntu12.04上安装了firefox,每次我杀死firefox并重新打开它时,都会出现一条消息,询问我是否要恢复以前的会话,这很烦人.

I am writing a program that needs to open a list of URLs. I have firefox on Ubuntu12.04, and every time I kill firefox and reopen it, there will be a message asking if I want to restore the previous sessions or not, which is quite annoying.

我使用

Runtime r= Runtime.getRuntime();
r.exec("firefox -new-instance www.google.com");

并使用

r.exec("killall firefox");

有没有一种方法可以更优雅地杀死并重新打开Firefox?我希望程序自动运行而没有任何弹出消息或人工干预. 非常感谢!

Is there a way to kill and reopen firefox more gracefully? I want the program run automatically without any pop-up messages or human intervention. Thanks a lot!

推荐答案

使用 WebDriver 进行加载和停止 Firefox .您可以使用单独的配置文件获得单独的Firefox实例.不会要求您还原会话.

Use WebDriver to load and stop Firefox. You can get a separate Firefox instance with a separate profile. You won't be asked to restore sessions.

FirefoxProfile fp = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(fp);
driver.get(url);

然后关闭浏览器和所有子窗口:

Then to close the browser and any child windows:

driver.quit();

这篇关于如何从命令行优雅地杀死firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆