groovy
String.execute()返回可能仍在运行的进程(取决于系统负载和天气)
如果要等到过程结束,请执行以下操作:
def txt = "cmd /c dir c:\".execute().with{ def output = new StringWriter() def error = new StringWriter() //wait for process ended and catch stderr and stdout it.waitForProcessOutput(output, error) //check there is no error assert error.toString().size()==0: "$error" //println it.exitValue() //we can do check with error pre //return stdout from closure return output.toString()}为
jenkins pipeline避免错误,请
java.io.NotSerializableException使用以下代码:
node { def res = runAndWait("cmd /c dir c:\") echo res}@NonCPSString runAndWait(Object cmd){ def proc = cmd.execute() def output = new StringWriter() def error = new StringWriter() //wait for process ended and catch stderr and stdout proc.waitForProcessOutput(output, error) //check there is no error assert error.toString().trim().size()==0: "$error" //assert proc.exitValue()==0 //we can do check with error pre //return stdout from closure return output.toString()}


