u123
u123

Reputation: 16287

Groovy execute process hangs

In a groovy script I execute an application on linux and windows with:

def proc = command.execute()
proc.consumeProcessOutput( System.out, System.err)
    println "here"
proc.waitFor()
    println "never here"

but the waitFor() call never returns. The strange thing is that it only happens on linux.

Based on this: process.waitFor() never returns

it could be caused by not reading from the appropriate streams. But as you can see I consume both System.out, System.err. Are there other streams that could be consumed?

Upvotes: 5

Views: 1816

Answers (1)

Opal
Opal

Reputation: 84786

I also had similar problem and the process being run was only hanging on jenkins CI server. It was a plutil command and consumeProcessOutputStream method was used.

Since there I use ProcessBuilder to construct and run processes.

def processBuilder = new ProcessBuilder('some command')
processBuilder.directory(new File('some dir')).environment().putAll([:])
processBuilder.redirectOutput(new File('out'))
processBuilder.redirectError(new File('err'))

Unfortunately no idea what causes Your problem.

Upvotes: 1

Related Questions