title: How to run PhantomJS from Tomcat web app
body: <p>I'm trying to run PhantomJS from a Grails application running on a Tomcat 7 instance on Linux (Ubuntu 13.04).</p>
  
  <p>I'm sure PhantomJS is installed correctly because I can execute it from the command line. I'm using it to make a screen capture of a web page (<a href="http://phantomjs.org/screen-capture.html" rel="nofollow">http://phantomjs.org/screen-capture.html</a>).</p>
  
  <p>When I run the command from the command line, it works great, using user root:</p>
  
  <pre><code>phantomjs /home/user/captureScreen.js "http://xx.xx.xx.xx/chart" "/home/user/07012014050636114.png"
  </code></pre>
  
  <p>I believe there is no need to share the JS code since it's working fine from the command line.</p>
  
  <p>The problem is that when I run the same command from the web-app (Grails), it just returns with a 0 value, which tells me everything ran fine, but it's not creating the PNG file neither returning an error.</p>
  
  <p>I'm calling the command from Groovy, this way:</p>
  
  <pre><code>String path = "phantomjs pathToJs.... etc"
  def process = path.execute()
  process.waitForOrKil(5000) // This runs in 1 to 2 seconds in the command line
  println process.exitValue()
  </code></pre>
  
  <p>I tried adding write permissions to the tomcat7 user to the folder where the JS file and where the image is written but still it didn't work but I still believe it's something related to permissions</p>
  
  <p>Any thoughts?</p>
  
  <p>Thanks!</p>