- execute().textを読み出そうとすると一部のコマンドで返ってこないことがある。
- どうやらWindowsではストリーム詰まる問題が出ることがあるらしい
元ソース
def runCommand(String command, String param) { def msg = [] def cmd = "C:/foo/bar/hogehoge.exe ${command} ${param}" def msg = cmd.execute([], new File("C:/foo/bar")).text.split() return msg }
- textを読み出そうとすると詰まる。
- textを読まなければ詰まらないのでコマンド自体は実行されている・・・
改善後
def runCommand(String command, String param) { def msg = [] def cmd = "C:/foo/bar/hogehoge.exe ${command} ${param}" def p = cmd.execute([], new File("C:/foo/bar")) // 一部のコマンドでStreamが詰まる問題のためThreadにしている Thread.start { p.in.eachLine {msg << it} } p.waitFor() return msg }
p.err.eachLine {}
が必要ならこちらもThreadにしたほうが良いかも。
うーん、出来たけどなんかすっきりしない。