Arturo
Arturo

Reputation: 1131

How to run PhantomJS from Tomcat web app

I'm trying to run PhantomJS from a Grails application running on a Tomcat 7 instance on Linux (Ubuntu 13.04).

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 (http://phantomjs.org/screen-capture.html).

When I run the command from the command line, it works great, using user root:

phantomjs /home/user/captureScreen.js "http://xx.xx.xx.xx/chart" "/home/user/07012014050636114.png"

I believe there is no need to share the JS code since it's working fine from the command line.

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.

I'm calling the command from Groovy, this way:

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()

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

Any thoughts?

Thanks!

Upvotes: 1

Views: 1239

Answers (1)

Grooveek
Grooveek

Reputation: 10094

As for command execution, we experienced problem in Grails applications concerning pure string notation. Using the array syntax

   ["/usr/binphantom/js","/home/user/captureScreen.js","http://xx.xx.xx.xx/chart","‌​/home/user/07012014050636114.png"].execute()

made the thing work. I think it has to do with shell expansion which differs on how strings are handled in Groovy.

Upvotes: 1

Related Questions