无法通过bash

时间:2015-11-27 04:52:50

标签: javascript node.js bash phantomjs casperjs

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

我能够通过符号链接在我的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$ 

我的问题是:我是否需要象征性地链接.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

如果您需要更多信息,请与我们联系,并感谢您抽出宝贵时间阅读我的问题! :)

1 个答案:

答案 0 :(得分:1)

您需要位于文件所在的文件夹中才能直接运行它。如果你在/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