Phantomjs 找不到 javascript 文件

Phantomjs can't find the javascript file

我是 Phantomjs 的新手,我刚刚下载了 Windows 的版本。 我打开了 bin 文件夹和 运行 phantomjs.exe:

中的命令
phantomjs hello.js

但它给了我错误:Expected an identifier bu found "hello" instead

然后我运行这个命令:

hello.js

我得到这个错误:找不到变量 hello

我的 hello.js

中有以下代码
console.log('Hello, world!');
phantom.exit();

我在同一个文件夹中有 hello.js 和 phantomjs.exe,但找不到 js 文件。我在网上搜索但找不到合适的解决方案。

感谢您的宝贵时间

我的错误是试图通过打开 bin 文件夹中的 phantomjs.exe 来执行命令 。我打开 windows cmd 并转到 phantomjs.exe 路径并且此命令有效:

phantomjs hello.js

所以不要尝试在 phantomjs.exe 上执行 运行 命令,而是打开你的 cmd

我也遇到过同样的情况,并且花费了不必要的时间来让它工作,所以我将一步一步地添加到 运行 你在 windows 上的第一个 phantomjs 程序中。

第 1 步:下载 phantomjs ( windows version )

第 2 步:解压缩下载的文件。

第三步:复制phantomjs的bin文件夹路径,并在环境变量中设置

第 4 步:转到您的 work_folder ,创建 hello.js

第 5 步:打开 cmd,使用以下命令转到您的 work_folder 和 运行 您的 hello.js

phantomjs hello.js

按照这些简单的步骤操作,如果您发现此错误 "Can't open hello.js"

  1. 假设您已经下载并安装在以下路径C:\PhantomJs
  2. 打开您的命令提示符。只需键入转到 phantom js 文件夹 C:\>cd phantomjs
  3. 只需键入 C:\PhantomJs>PhantomJs hello.js 您应该能够看到输出 hello world