Created
July 8, 2011 13:06
-
-
Save AlexanderWingard/1071780 to your computer and use it in GitHub Desktop.
ScalaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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