【问题标题】:Mac OSX Running Application in bash, alias not workingMac OSX 在 bash 中运行应用程序,别名不起作用
【发布时间】:2018-04-14 05:33:40
【问题描述】:

我正在尝试在 rake 任务中调用无头 Chrome。它适用于终端,但不适用于 rake 任务。

我在 Mac OS X 上安装了 Chrome,并为应用程序创建了一个别名:alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"

命令chrome --version 产生输出:Google Chrome 61.0.3163.100

which chrome 不产生任何输出,这看起来很奇怪。 chrome --headless --disabled-gpu 按预期打开和关闭 chrome 会话。

我想在 Rails 环境中运行 headless chrome,并进行 rake 测试:

namespace :chrome do
  task test_versions: :environment do
    p `chrome --version`
  end
end

然后运行 ​​rake 任务:rake chrome:test_versions,结果: /User/username/.rvm/gems/ruby-2.4.2/bin/rake: No such file or directory - chrome

编辑:在几次 cmets 之后,我并没有解决真正的问题。我想在 Mac 中使用 rake 任务来调用 chrome headless。

【问题讨论】:

  • 使用 `` 没有在你的 shell 中运行,它通过sh 在子 shell 中运行。
  • system %(source ~/.bash_profile \n chrome --version) 有效,有没有办法在 rails shell 命令的 bash_profile 中包含别名?
  • Shell 别名实际上是为交互使用而设计的;他们几乎肯定是做任何你真正想要完成的事情的错误方法。请阅读XY Problem,并告诉我们您真正想要做什么。

标签: ruby-on-rails ruby bash macos google-chrome


【解决方案1】:

which chrome 不产生任何输出,这似乎很奇怪。

which 是一个外部命令,它知道 Bash 的别名。你可以使用 Bash 的type 命令:

# type chrome

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    相关资源
    最近更新 更多