Search code examples
cygwinphantomjs

unable to run PhantomJS under cygwin using absolute paths


I am not able to run PhantomJS under cygwin using absolute paths for the argument .js file. Here are the steps I took to setup PhantomJS:

  1. Downloaded PhantomJS 1.9.7 for windows

  2. Copied the PhantomJS executable to c:\cygwin64\bin\

  3. Copied the file "hello.js" from the unzipped PhantomJS download file to my cygwin home directory

  4. Started cygwin/xterm

If I run:

which phantomjs

in my cygwin xterm, it correctly responds with:

/usr/bin/phantomjs

If I run the following from my home directory:

phantomjs hello.js

PhantomJS correctly responds with:

Hello, world! 

If I on the other hand run this:

phantomjs /home/user1/hello.js

PhantomJS replies:

Can't open '/home/user1/hello.js'

If I run this:

/usr/bin/phantomjs /home/user1/hello.js

PhantomJS still replies:

Can't open '/home/user1/hello.js'

It does this for every absolute path I try. Why won't PhantomJS work with absolute file paths? The path I showed in my example doesn't have any spaces, special characters, etc., so I'm not sure what the problem could be.

I also tried running the same test in a command prompt under windows and sometimes it would exhibit the same behavior, but not always. I can't seem to reproduce this error under windows anymore so I'm not sure what else to say about that.

Does anyone know what the problem could be?


Solution

  • I found the solution. Running native windows programs through cygwin requires you to convert cygwin's POSIX paths to Windows-style paths. In my example above, the following works:

    phantomjs "`cygpath -w /cygdrive/c/cygwin64/home/user1/hello.js`"
    

    returns:

    Hello, world!
    

    I am not yet sure what the backticks are for, but at least I found the solution.