使用命令行参数作为后台进程运行 Mac Chrome
我的 .bash_profile
文件中有 2 个别名,其中包含:
alias chrome="/Applications/Google\\ \\Chrome.app/Contents/MacOS/Google\\ \\Chrome"
alias chromex="chrome --disable-web-security"
但运行时,它会打开 Chrome,但保持终端窗口...一旦我关闭终端窗口,它也会关闭 chrome。
有什么办法让它在后台运行吗?
我记得我将其用于 thin
网络服务器,并使用 thin start -d
或 thin start --daemonize
?
感谢
更新,
除了詹姆斯的回答之外,我还发现了 nohup
命令行,它使我可以毫无问题地退出终端,这是通过将 &
附加到 nohup
命令:
$ nohup chromex &
默认输出写入 nohup.out
文件
要停止作业,我可以运行 ps ax
,通过正确的命令找到 PID,然后然后kill -9 PID
I have 2 aliases on my .bash_profile
file containing:
alias chrome="/Applications/Google\\ \\Chrome.app/Contents/MacOS/Google\\ \\Chrome"
alias chromex="chrome --disable-web-security"
but when running, it opens up Chrome but keeps holding the terminal window...once I close the terminal window it also closes chrome.
Is there any way to make it run in the background?
I remembered I use this for thin
webserver with thin start -d
or thin start --daemonize
?
Thanks
update
besides James answer I also found the nohup
command line which made possible for me to quit terminal without problem that was a mix by appending the &
to the nohup
command:
$ nohup chromex &
the default output is written to the nohup.out
file
To stop the job I can run ps ax
, find the PID though the right command and then kill -9 PID
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在命令行末尾放置一个 & 符号。
如果您也不想看到任何调试 chrome 输出,请将 stdout 和 stderr 重定向到 /dev/null
在 Mac 上,您可以使这变得更加简单:
不过,您的第二个要求使这稍微有点棘手。的&需要位于命令行的末尾;但是您的第二个别名将命令添加到第一个命令的末尾 - 即在&符号之后 - 所以这不起作用。
为了解决这个问题,我们可以将“chrome”重新定义为一个函数。
$*
表示传递给函数的任何命令行参数都将插入此处,位于与号之前。这意味着您仍然可以定义第二个别名,因为这将扩展到
BTW,这只是称为“在后台”运行。 “作为守护进程”是指每当计算机打开时运行的服务器进程,并且不依赖于任何用户的会话。
Put an ampersand on the end of the commandline.
If you also don't want to see any of the debugging chrome outputs, redirect stdout and stderr to /dev/null
On Mac, you can make this even simpler:
Your second requirement makes this slightly trickier though. The & needs to be at the end of the commandline; but your second alias adds commands to the end of the first command - ie, after the ampersand - and so this doesn't work.
To get around this, we can redefine 'chrome' as a function.
The
$*
means that any commandline parameters passed to the function will be inserted here, before the ampersand. This means you can still define your second alias asThis will be expanded out to
BTW, this is just referred to as running "in the background". "As a daemon" would refer to a server process that runs whenever the machine is turned on, and is not tied to any user's session.
我在 .zshr 上定义了别名(与 .bash_profile 相同),如下所示:
然后我可以通过 Firefox 或 Chrome 打开 html 文件,
例如通过 Firefox
通过 Chrome
I defined alias on my .zshr (same for .bash_profile) like this:
then I can open html file by Firefox or Chrome
for example, by Firefox
by Chrome