下記の例では、Pandocのバージョン情報を出力している。(Pandocをインストールしていない場合は、実行可能なコマンドに適宜変更すること。なお、Pandocのインストールについては『PandocをWindowsにインストールする』を参照。)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def proc = "pandoc -v".execute() | |
proc.waitFor() | |
println proc.in.text | |
// if you just want stdout of the command, you can write as: | |
println "pandoc -v".execute().text |
実行したいコマンドからなる文字列のexecuteメソッドを呼び出すことにより、コマンドの実行を非同期で開始する(1行目)。このメソッドはjava.lang.Processを返す。コマンドの実行が完了するのを待って(2行目)、標準出力の内容をprintlnしている(3行目)。
なお、コマンドが標準出力に出力した内容を確認したいだけなら、6行目のように記述することも可能。
0 件のコメント:
コメントを投稿