/** * Created by neko32 on 2016/01/03. */ object RunCommand { def main(args:Array[String]):Unit = { import sys.process._ // execute external command val result = "javac -version".! println(result) // return stdout val result2 = "javac -version".!! println(result2) // via Process or Seq command can be triggered val result3 = Seq("javac", "-version").!! println(result3) val result4 = Process("javac -version").!! println(result4) // dump stderr val result5 = "javac -takorin".lineStream_!.mkString println(result5) // redirect output to a file val result6 = ("javac -version" #> new File("C:\\tmp\\javav")).! println(result6) // this step may not work on Windows assume(new File("C:\\tmp\\javav").exists() && Source.fromFile("C:\\tmp\\javav").mkString.length() > 0, "file should exists!") } }
しかしながらscalaはパイプを用意に実現できたりとより強力である.
scala> ("ls /cygdrive/c/tmp/" #| "grep -i rachmaninov").!!.trim res1: String = Rachmaninov_piano3.jpg Rachmaninov2.jpg
0 件のコメント:
コメントを投稿