how to kill firefox gracefully from command line

北城以北 提交于 2019-12-24 01:53:15

问题


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.

I invoke firefox(in Java) using

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

and kill it using

r.exec("killall 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!


回答1:


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();



回答2:


I think you cannot kill Firefox gracefully from Java, but you can change your firefox settings so that it wont ask you everytime it re-opens.

See the link Firefox Restore Options which will help you.




回答3:


Instead of launching firefox directly, launch a shell script that launches firefox in the background, then prints the PID of the firefox process on the standard out.

Then you can read the PID back through the Process object returned by Runtime.exec()



来源:https://stackoverflow.com/questions/13961724/how-to-kill-firefox-gracefully-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!