Using CasperJS as a Portable Installation?

2019-02-20 13:01发布

问题:

I'm trying to run CasperJS in a portable way that doesn't involve setting the path variable in Windows. Currently I have gotten this to partially work by moving the phantomjs executable along with the entire contents of the CasperJS directory to the batchbin folder. I also edited the batch file to make it initialize casperJS using the current directory, which is where all the files are located.

Here is my directory with all the files: http://i.imgur.com/ByTjU0s.png

My casperjs.bat file:

    @ECHO OFF
    set CASPER_PATH=%~dp0
    set CASPER_BIN=%CASPER_PATH%bin\
    set ARGV=%*
    call phantomjs "%CASPER_BIN%bootstrap.js" --casper-path="%CASPER_PATH%" --cli %ARGV%

When I try to execute the file it gives me: http://i.imgur.com/0DK6B2g.png

I tried to look at the bootstrap.js file to make it bypass the version check so it won't give me this error, but I'm not really sure what I'm doing.

How can I run casperJS as a portable without setting the path variable and having everything in one single directory?

回答1:

try it without call:

phantomjs "%CASPER_BIN%bootstrap.js" --casper-path="%CASPER_PATH%" --cli %ARGV%


回答2:

Got it to work. For the casperjs.bat file, put:

@ECHO OFF
set CASPER_PATH=%~dp0..
set CASPER_BIN=%CASPER_PATH%\bin\
set ARGV=%*
call phantomjs "%CASPER_BIN%bootstrap.js" --casper-path="%CASPER_PATH%" --cli %ARGV%

Move the phantomjs.exe executable to the same directory as this batch file. Should work fine.