外部プロセスの実行/制御

最終更新日: 01 年 2020 月 XNUMX 日

外部プロセスを呼び出す最も堅牢な方法は、Groovyメソッドを使用することです waitForProcessOutput。

例:

command = "../ bin / ipmiutil sensor -c -N" + hostname + "-U" + User + "-P" + Pass def sout = new StringBuffer()def serr = new StringBuffer()def proc = command.execute ()proc.waitForProcessOutput(sout、serr)if(proc.exitValue()== 0){output = sout.toString()output.eachLine {if(it =〜/ Full /){elements = it.split(/ * \ | * /)if(elements [5] == "OK"){//ステータスを報告しているもののみを検出するprintln elements [0] + "##" + elements [4] + ":" + elements [3 ]}}} else {//エラー処理...}