sbt/util/process/src/test/scala/TestedProcess.scala

47 lines
1.2 KiB
Scala
Raw Normal View History

package sbt
2014-05-07 17:52:23 +02:00
import java.io.{ File, FileNotFoundException, IOException }
2014-05-07 17:52:23 +02:00
object exit {
def main(args: Array[String]) {
System.exit(java.lang.Integer.parseInt(args(0)))
}
}
2014-05-07 17:52:23 +02:00
object cat {
def main(args: Array[String]) {
try {
if (args.length == 0)
IO.transfer(System.in, System.out)
else
catFiles(args.toList)
System.exit(0)
} catch {
2014-12-03 18:56:34 +01:00
case e: Throwable =>
2014-05-07 17:52:23 +02:00
e.printStackTrace()
System.err.println("Error: " + e.toString)
System.exit(1)
}
}
private def catFiles(filenames: List[String]): Option[String] =
{
filenames match {
case head :: tail =>
val file = new File(head)
if (file.isDirectory)
throw new IOException("Is directory: " + file)
else if (file.exists) {
Using.fileInputStream(file) { stream =>
IO.transfer(stream, System.out)
}
catFiles(tail)
} else
throw new FileNotFoundException("No such file or directory: " + file)
case Nil => None
}
}
}
2014-05-07 17:52:23 +02:00
object echo {
def main(args: Array[String]) {
System.out.println(args.mkString(" "))
}
}