I\'m looking to replace a lot of my perl with scala. One of the things I tend to do a lot is call binaries (usually compiled C++, but could be java, other perl scripts, q sc
You can wait for the end of a process calling exitValue
. You might do that in a separate thread, in which the callback will happen. Maybe class Process
could be pimped thus:
import scala.concurrent.ops.spawn
implicit def ProcessWithCallback(p: Process) {
def whenTerminatedDo(callback: Int => Unit) = spawn{
val exitValue = p.exitValue; callback(p)
}
}
You could then use that in Exe
as you like.
The Process
class given by the JVM and wrapped by scala.sys.Process
is really rather feable, it will be hard not to block a thread