Files
Packer-Cn/packer/plugin/command.go
T

38 lines
615 B
Go
Raw Normal View History

2013-05-04 21:26:30 -07:00
package plugin
import (
"bytes"
"github.com/mitchellh/packer/packer"
"net/rpc"
"os/exec"
packrpc "github.com/mitchellh/packer/packer/rpc"
"strings"
"time"
)
func Command(cmd *exec.Cmd) packer.Command {
2013-05-04 21:26:30 -07:00
out := new(bytes.Buffer)
cmd.Stdout = out
cmd.Start()
2013-05-04 21:26:30 -07:00
// TODO: timeout
// TODO: check that command is even running
address := ""
for {
line, err := out.ReadBytes('\n')
if err == nil {
address = strings.TrimSpace(string(line))
break
}
time.Sleep(10 * time.Millisecond)
}
client, err := rpc.Dial("tcp", address)
if err != nil {
panic(err)
}
2013-05-04 21:26:30 -07:00
return packrpc.Command(client)
2013-05-04 21:26:30 -07:00
}