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.
views:
195answers:
2It's not quite right to even say that Java does this, because of differing process/stream handling on different operating systems, much of this functionality is actually passed off to native code.
A more interesting question would then be to ask if Scala has any way to work more "idiomatically" with readers and writers (or channels if you're wrapping your streams with NIO functionality)
And the answer?
At the moment there is work underway on a scala IO library to be based on 2.8, this will almost certainly include a better way to work with streams and channels, but isn't yet available.
You might also find actors to be a better way of handling the common practice of using one thread for input and one thread for output when dealing with an exec()'d process.
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.