Skip to content

Instantly share code, notes, and snippets.

@jorgeortiz85
Created August 16, 2011 23:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeortiz85/1150438 to your computer and use it in GitHub Desktop.
Save jorgeortiz85/1150438 to your computer and use it in GitHub Desktop.
Scala Process Library
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