Skip to content

Instantly share code, notes, and snippets.

@AlexanderWingard
Created July 8, 2011 13:06
Show Gist options
  • Save AlexanderWingard/1071780 to your computer and use it in GitHub Desktop.
Save AlexanderWingard/1071780 to your computer and use it in GitHub Desktop.
ScalaScript
#!/bin/sh
L=`dirname $0`/lib
cp=`echo $L/*.jar|sed 's/ /:/g'`
exec scala -savecompiled -classpath $cp $0 $@
!#
// /* */ */
val cmd1 = Cmd("ping localhost")
val cmd2 = Cmd("vmstat 1")
for(i <- 1 to 5) {
println(cmd1.next)
println(cmd2.next)
}
// Script util stuff:
import scala.collection.JavaConversions._
import scala.io.Source
object Cmd {
def apply(cmd : String) = {
val process = new ProcessBuilder(cmd.split(" ").toList).start
Source.fromInputStream(process.getInputStream).getLines
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment