对我如何执行 PhantomJS 文件感到困惑。初学者需要建议。 [苹果系统]

Confused about how I execute a PhantomJS file. Beginner needing advice. [MacOS]

我目前正在尝试在我的终端中执行 hello.js 示例文件,但完全失败了。我在网上找到的例子要么让我输入:

phantomjs hello.js

我的终端机returns

Can't open 'hello.js'

或者对我来说是绝对文件路径

/usr/local/Cellar/phantomjs/2.1.1/share/phantomjs/examples/hello.js

我的终端机returns

-bash: /usr/local/Cellar/phantomjs/2.1.1/share/phantomjs/examples/hello.js: Permission denied

我在这里做错了什么? :(

提前致谢。

Screenshot

要运行 Phantomjs 中的文件,您需要为 phantomjs 提供文件的完整路径:

phantomjs /usr/local/Cellar/phantomjs/2.1.1/share/phantomjs/examples/hello.js

或者您可以通过将 examples 目录复制到易于访问的地方(例如您的主目录)

来让自己的生活更轻松一些
cp -r /usr/local/Cellar/phantomjs/2.1.1/share/phantomjs/examples ~/

~/ 是您主目录的快捷方式;您可以使用 Finder 到 examples 目录到您的主目录)

在终端中切换到该目录

cd ~/examples

然后运行宁

phantomjs hello.js