Created
August 16, 2011 23:29
-
-
Save jorgeortiz85/1150438 to your computer and use it in GitHub Desktop.
Scala Process Library
This file contains 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
import scala.sys.process._ | |
import java.io._ | |
// Run a Process, return the output as a String | |
Process("echo foo") !! | |
// Run a Process, pipe in some input, and return the output as a String | |
Process("cat") #< (new ByteArrayInputStream("foobar".getBytes("UTF-8"))) !! | |
// Run a Process, pipe in some input, and pipe the output to a Array[Byte] | |
val output = new ByteArrayOutputStream | |
Process("cat") #< (new ByteArrayInputStream("foobar".getBytes("UTF-8"))) #> output ! | |
output.toByteArray | |
// Scala Process Library Operators: | |
// ! - run the process, return the exit code as an Int | |
// !! - run the process, return the output as a String | |
// #< - pipe into the process | |
// #> - pipe out from the process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment