Gradle Execute external program

Dear my friends,

I faced a problem when executing external program with Gradle. Hope you will help me to solve this. Thank you all :slight_smile:
PS: I used Gradle for an embedded project (C language not a Java project)
I will describe my problem:

  1. My development environment is Ubuntu.
  2. I used an external program for Unit test (It is called Cantata), From Linux I will type a command “./cantpp” to invoke its GUI (eclipse based)
  3. After finishing working on GUI I will integrate last result to Gradle so that Gradle will invoke a command line to generate Test Report.
    The command line like below:

$CANTATA_INSTALL_DIR/cantpp -application com.ipl.products.eclipse.cantpp.testscript.TestSummaryGenerator -noSplash -data Cantata/UnitTest project=Cantata/UnitTest/abcdef 1 (with this command like on shell the GUI will not be invoked by option ‘-noSplash’, and I get the report successfully)

And Gradle code for that command line is:

def commandArray = new String[3]
commandArray[0] = System.getenv(“CANTATA_INSTALL_DIR”) + "/cantpp"
commandArray[1] = "application"
commandArray[2] = "com.ipl.products.eclipse.cantpp.testscript.TestSummaryGenerator -noSplash -data Cantata/UnitTest project=Cantata/UnitTest/gDMPxy 1"
def process = new ProcessBuilder(commandArray)
.directory(new File(curPath))
.redirectErrorStream(true)
.start()
process.inputStream.eachLine {println it}
process.waitFor();

But unfortunately, when Gradle is running, the GUI is invoked so the command line is not executed like I expect.

So my question is “Are there any ways to execute the command line in Gradle which the GUI is not invoked?”

Thanks and Best regards
Tuan

This line is the problem. When building a process, every argument needs to go in a separate element of the array.

Also, why are you using ProcessBuilder instead of Gradle’s much more covenient Exec task or exec method?

1 Like

Dear friend,
Tks for your answer
I tried
def commandArray = new String[4]
commandArray[0] = System.getenv(“CANTATA_INSTALL_DIR”) + “/cantpp”
commandArray[1] = “application com.ipl.products.eclipse.cantpp.testscript.TestSummaryGenerator”
commandArray[2] = “noSplash”
commandArray[3] = “data Cantata/UnitTest project=Cantata/UnitTest/gDMPxy 1”
def process = new ProcessBuilder(commandArray)
.directory(new File(curPath))
.redirectErrorStream(true)
.start()
process.inputStream.eachLine {println it}
process.waitFor();
But it not work.

I also tried Exec and exec but it also not work

Best regards
Tuan