views:

45

answers:

0

Hey all,

I am writing some simple Scala code to control the lifecycle of a MySQL server (start it, create appropriate tables and users, etc...) on Windows XP.

For example, I have a function which starts the mysql daemon in an external shell. The function should exit as soon as mysql has started (it must not wait for it to be finished).

When I run the code from Intellij IDEA, then the JVM exits as soon as MySQL has started. Likewise when I run the code (packaged as a jar) from the command line, I see the same behaviour.

However, when I run it from Eclipse, the JVM hangs as long as the mysql server remains alive. I am not sure why this is the case. Any clues?

I am using Eclipse 3.5.2 with the Scala plugin.

Here is the code:

import java.io.File

object DBTest{
    def main(args : Array[String]){
            val mysqlHomeDirectory=new File("C:\\ProjectFolders\\mysql")
    val iniFile = "default.ini"
    val port = 3309
    val serverID = 10
    val command = "bin\\mysqld --defaults-file=" + iniFile + " --standalone --console --server_id=" + serverID + " --port=" + port
    val pb = new ProcessBuilder( ("cmd /c start " + command).split(" "):_*)
    pb.directory( mysqlHomeDirectory)
  pb.directory()
  pb.start
    }

}

Here is an even simpler example which also blocks the Eclipse JVM:

object ProcessTest{
    def main(args : Array[String]){
    var command = "dir *.*"
    val pb = new ProcessBuilder( ("cmd /c start " + command).split(" "):_*)
  pb.directory()
  pb.start.waitFor
  println ("The external process has completed.. So the jvm shoud shut down....")
    }
}

When I run this, I see:

The external process has completed.. So the jvm shoud shut down....

This is the correct message, but however, the JVM does not shutdown on Eclipse.