Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any Scala built-in class for capturing an external process's output?

Tags:

process

scala

Since Scala has so many cool stuff I was thinking it may have something that makes capturing a process's output easy. I know the Java way of doing that, but I thought about asking for another way.

like image 562
Geo Avatar asked Jan 28 '10 16:01

Geo


2 Answers

scala> scala.tools.nsc.io.Process("ls -1 /tmp | wc").stdout foreach println
      41      63     770

Or there's a repl command:

scala> :sh cat /etc/passwd | wc
stdout: List[String] = List(      65     185    3667)

Shipping any IO code with 2.8 was going to require overcoming more stop energy than I can beat, so I put it all in the compiler. Plenty of reasonably useful stuff in scala.tools.nsc.io.

like image 166
psp Avatar answered Sep 24 '22 16:09

psp


As of Scala 2.9, you can do:

import scala.sys.process.Process
println(Process("uname -a").!!.contains("x86_64"))
like image 40
Chris Oei Avatar answered Sep 24 '22 16:09

Chris Oei