子プロセスでCGI(PHP)を実行して親プロセスの出力ストリームに書き込み

def execCgi() {
  try {
    val arg = Array( "/Applications/XAMPP/xamppfiles/bin/php", file.getName() );
    val cgiProcess: Process = Runtime.getRuntime().exec( arg );
    val input: BufferedReader = new BufferedReader( new InputStreamReader( cgiProcess.getInputStream() ) );
    val output: PrintStream = new PrintStream( socket.getOutputStream() );

    var line = input.readLine();
    while( line ne null ) {
      output.println( line );
      line = input.readLine();
    }
  } catch {
    case e: IOException => {
      println( e.getMessage() );
      throw e;
    }
  }
}

うーん、ネットワーク周りの独自APIはないっぽいから、Javaで書くのとほとんど変わらない。
スレッド生成がActorになるくらいか。
java.nio.*」を使う場合は、Actorも使わないだろうからやっぱりJavaと変わらないな。。。
scala/tools/util/SocketConnection.scalaとかを見てもそうなってるし、やっぱこれでいっか。


あ、XAMPPのPHPはenable-cgi付きでビルドされてるので便利です。