通过命令行关闭谷歌浏览器在应用程序模式下打开 [英] Close google chrome open in app mode via command line
问题描述
在我的python脚本中,我使用以下命令在app模式下打开chrome:
google-chrome --app = http://stackoverflow.com
现在我想成为能够关闭只有这个正在运行的chrome应用程序(我的意思是如果有另一个chrome窗口与不同的选项卡我不想关闭,只有这个我运行)。这是可能的和如何?
我使用的是linux。
编辑:
至于我设法做这样的事情:
导入子流程
proc = subprocess.Popen(['google 'chrome',
'--user-data-dir = / home / chrome-user','http://google.pl'])
#做某事
proc.terminate()
当我从命令行调用这个python脚本时,没问题。我的问题是在我作为linux服务运行时(在/ etc / init下)开始的。我记录和一切都好,除了谷歌Chrome浏览器似乎无法创建窗口或什么?我的意思是没有错误,但谷歌浏览器窗口根本没有显示。
编辑2:
绝对是启动时遇到的问题。当我在启动时运行它:
mate-terminal -epython3
/path/to/script/script.py
除了显示终端窗口外,一切正常。所以,这不知怎的解决了我的问题,但如果任何人会有任何消化,我可以做什么,我会高度apreciate它。
所以很长一段时间后我回答了。在linux mint中,您需要将其添加到启动程序中:
mate-terminal -epython3 / path / to / script / script。如果你想以root用户的身份运行脚本,这是它的解决方案(它非常丑陋,但工作原理):py
mate-terminal -ebash -cecho pass | sudo -S python3 /path/to/script/script.py; $ SHELL'
In my python script I am opening chrome in app mode by this command:
google-chrome --app=http://stackoverflow.com
Now I want to be able to close only this running chrome application (I mean if there is another chrome windows with diffrent tabs I don't want to close that, only this that i run). Is this possible and how?
I am using linux.
EDIT: As far i manage to do something like this:
import subprocess
proc = subprocess.Popen(['google-chrome',
'--user-data-dir=/home/chrome-user', 'http://google.pl'])
# do something
proc.terminate()
And when I call this python script from command line everything is ok. My problem starts when I am running this as a linux service (under /etc/init). I logged and everything is ok except that google chrome seems to not be able to create window or something? I mean there is no error but google chrome window doesn't shows at all.
EDIT 2: Definitely it is a problem with startup. When i run this on startup:
mate-terminal -e "python3 /path/to/script/script.py"
Everything works fine except that terminal windows is shown. So this somehow solves my problem but if anyone will have got any sugestion what can i do i would highly apreciate it.
Ok so after a long time I come with answer. In linux mint you need to add this to startup programs:
mate-terminal -e "python3 /path/to/script/script.py"
and if you want to run script as root user, this is solution for it (it's very ugly, but works):
mate-terminal -e "bash -c 'echo pass | sudo -S python3 /path/to/script/script.py;$SHELL'"
这篇关于通过命令行关闭谷歌浏览器在应用程序模式下打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!