Ali insan Soyaslan
Ali insan Soyaslan

Reputation: 846

Phantomjs can't find the javascript file

I am new to Phantomjs I just downloaded its version for Windows. I opened the bin folder and run the command in phantomjs.exe:

phantomjs hello.js

But it gives me the error : Expected an identifier bu found "hello" instead

Then I run this command:

hello.js

I get this error : Can't find variable hello

I have following codes in my hello.js

console.log('Hello, world!');
phantom.exit();

I have hello.js and phantomjs.exe in same folder,but it can't find the js file. I searhed over web but could not find an appropiate solution.

Thanks for your time

Upvotes: 1

Views: 2334

Answers (3)

Vinit Kadkol
Vinit Kadkol

Reputation: 1295

Follow these simple steps, if you find this error "Can't open hello.js"

  1. Assume you have downloaded and installed in this following path C:\PhantomJs
  2. Open your cmd prompt. Just type go to phantom js folder C:\>cd phantomjs
  3. Just type C:\PhantomJs>PhantomJs hello.js you should be able to see the output as hello world

enter image description here

Upvotes: 0

Scarecrow
Scarecrow

Reputation: 4137

I've also failed into same situation and spend unnecessary time to make it work, So I am adding step by step procedure to run your first phantomjs program on windows.

Step 1: Download phantomjs ( windows version )

Step 2: unzip the downloaded file.

Step 3: copy the path to phantomjs's bin folder, and set it in environment variable

Step 4: go to your work_folder , create hello.js

Step 5: open cmd , go to your work_folder and run your hello.js using following command

phantomjs hello.js

Upvotes: 0

Ali insan Soyaslan
Ali insan Soyaslan

Reputation: 846

My mistake was trying to execute commands by opening the phantomjs.exe in bin folder. I opened windows cmd and go to the path of phantomjs.exe and this command worked:

phantomjs hello.js

So don't try to run commands on phantomjs.exe, open your cmd instead

Upvotes: 7

Related Questions