Skip to content

Instantly share code, notes, and snippets.

@EmielM
Created June 4, 2010 12:06
Show Gist options
  • Save EmielM/425327 to your computer and use it in GitHub Desktop.
Save EmielM/425327 to your computer and use it in GitHub Desktop.
func Launch(vbox *VBoxSpec, statusch chan<- *VmStatus, quitch <-chan bool) {
go func() {
vboxPath := main.Config["VboxPath"]
vboxHeadlessBin := fmt.Sprintf("%s/VBoxHeadless", vboxPath)
statusch <- VmStatus{vbox, VMSTATUS_LAUNCHING}
var stdoutFilePtr *File
pid, err := os.ForkExec(vboxHeadlessBin,
[]string{"-s", "winxp", "-v", "on", "-p", "12345"},
[]string{},
[]*File{stdoutFilePtr}
vboxPath)
stdout := readerToChannel(*stdoutFilePtr)
stdoutBuf := bytes.NewBuffer(make([]byte, 0, 256))
stdoutScanner := SOME_SCANNER(stdoutBuf)
select {
case s := <-stdout:
stdoutBuf.Write(s)
if stdoutScanner.hasNextLine() {
// etc.
}
case <-quitch:
// Send signal, wait and clean up
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment