Skip to content

Instantly share code, notes, and snippets.

@jessta
Forked from EmielM/gist:425327
Created June 4, 2010 12:16
Show Gist options
  • Save jessta/425341 to your computer and use it in GitHub Desktop.
Save jessta/425341 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