0

I just started experimenting with phantomjs via terminal/bash Version 2.5.3 (343.7), on osx 10.10.4. The ready to use binary was installed.

I was able to set phantomjs on my PATH with symbolical linking. Prior to that I had to directly launch the executable or enter its absolute path.

When I try to launch a .js file with phantomjs, for example hello.js, I get " Can't open 'hello.js' ". If I enter the absolute path of the .js file it works:

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$ 

My question is: Do I need to symbolically link the folder where the .js files are located with /usr/local/bin/ to ensure that it is also on my PATH or is there another way that the .js files can be launched with phantomjs, without having to enter the absolute path every time?

I did search before posting this question but I'm uncertain as to how I should interpret everything I found :( The most significant, and somewhat relevant information I found referenced to node.js as the default to execute .js files in terminal.

Please note that currently, the hello.js file I am using is located in

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

and phantomjs is located in

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

Please let me know if you need further information and thank you for taking the time to read my question! :)

1 Answer 1

1

You need to be in the folder that the file is in to run it directly. If you are in the folder /Users/john/Documents/phantomjs-1.9.2-macosx/examples/ you should be able to run 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
Sign up to request clarification or add additional context in comments.

2 Comments

@dryor Ah! It works now! :) Thank you so much for you clear and concise answer! Is this a general rule to run files from bash with the exception of executables that are on the PATH?
@dryor Nice! I really appreciate your help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.