无法通过 bash 使用 phantomjs 打开 javascript 文件

can't open javascript files with phantomjs via bash

我刚刚在 osx 10.10.4 上通过 terminal/bash 版本 2.5.3 (343.7) 开始试验 phantomjs。已安装随时可用的二进制文件。

我能够使用符号 linking 在我的 PATH 上设置 phantomjs。在此之前,我必须直接启动可执行文件或输入其绝对路径。

当我尝试使用 phantomjs 启动 .js 文件时,例如 hello.js,我得到“无法打开 'hello.js'”。如果我输入 .js 文件的绝对路径,它会起作用:

console.log('Hello, world! It works :D');
phantom.exit();



Johns-MacBook-Pro:~ john$ phantomjs hello.js
Can't open 'hello.js'

VS

console.log('Hello, world! It works :D');
phantom.exit();


Johns-MacBook-Pro:~ john$ phantomjs /Users/john/Documents/phantomjs-1.9.2-macosx/examples/hello.js 
Hello, world! It works :D
Johns-MacBook-Pro:~ john$ 

我的问题是:我是否需要象征性地 link .js 文件所在的文件夹 位于 /usr/local/bin/ 以确保它也在我的 PATH 上或者是否有另一种方式 .js文件可以用phantomjs启动,不用每次都输入绝对路径?

我在发布这个问题之前进行了搜索,但我不确定我应该如何解释我发现的所有内容:(我发现最重要、最相关的信息参考了 node.js 作为默认执行终端中的 .js 文件。

请注意,目前,我正在使用的 hello.js 文件位于

/Users/john/Documents/phantomjs-1.9.2-macosx/examples/hello.js

而 phantomjs 位于

/Users/john/Documents/phantomjs-1.9.2-macosx/bin/phantomjs

如果您需要更多信息,请告诉我,感谢您花时间阅读我的问题! :)

您需要在文件所在的文件夹中直接 运行 它。如果你在文件夹 /Users/john/Documents/phantomjs-1.9.2-macosx/examples/ 你应该可以 运行 phantomjs hello.js.

# Change directory to where the file is you want to run in phantom
cd /Users/john/Documents/phantomjs-1.9.2-macosx/examples/

# Run the file with phantom
phamtomjs hello.js