Search code examples
javabashmacosphantomjsprocessbuilder

How to run phantomjs script from java?


I have the following code in my java application. I am always getting an exit status of 1. I have no idea why this fails. When I run which phantomjs in my terminal manually, I get the path as expected. Other commands like ls and which bash for example, return status 0.

process = new ProcessBuilder("which","phantomjs").start();
int status = process.waitFor();

What am I doing wrong and how to fix this?


Solution

  • I figured out what I had done wrong. I was running this in my java code inside of eclipse. I didn't know that I have to set environment variables separately for eclipse. When I ran the code outside of eclipse by creating a runnable jar, it worked as expected.