Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't Groovy find this program even though it's on my PATH?
    primarykey
    data
    text
    <p><strong>tl;dr:</strong> Groovy cannot find a program (<code>phantomjs</code>, which is on my <code>$PATH</code>) when I attempt to execute the shell command from a class -- it's otherwise finds it just fine from the Groovy Console or from a Grails CLI script. What gives?</p> <p>We have a Grails script to execute JavaScript unit tests in PhantomJS ("the headless WebKit"). When these tests are executed in a stand-alone script (call it <code>grails test-js</code>) things work just fine. The relevant line from the Grails/Gant script was:</p> <pre><code>// where 'jsTests' is a List with the paths to each test def failures = 0 jsTests.each { Process p = "phantomjs lib/phantom-jasmine/lib/run_jasmine_test.coffee file://${it}".execute() failures += p.exitValue() } </code></pre> <p>But since we want this to run as part of the usual <code>grails test-app</code> cycle, we created an implementation of <code>org.codehaus.groovy.grails.test.GrailsTestType</code>. When we get to the part in that implementation where we need to execute the tests, that same code (as above) doesn't work, and Groovy/Grails complains that:</p> <pre><code>java.io.IOException: Cannot run program "phantomjs": error=2, No such file or directory </code></pre> <p>My first thought was that <code>phantomjs</code> was not on my <code>$PATH</code> -- but I know that it is, and again: it worked when run from the Grails/Gant script. So I tried it in the Groovy Console, and it works OK from there.</p> <p>Now, if I switch from <code>phantomjs</code> to <code>/absolute/path/to/phantomjs</code>, then it works fine. But hard-coding an absolute filesystem path into the class cannot be the solution.</p> <p>So: why isn't Groovy finding <code>phantomjs</code> under those circumstances?</p> <p><strong>Update:</strong> I suspect that this might have something to do with my IDE (IntelliJ Idea), as this error doesn't appear to be happening when running this from the command line.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload