beam/examples/beamsh: simple 'exec' command

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-03-25 10:14:52 -07:00
Родитель 5689792171
Коммит ab2010cfd3
1 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -4,6 +4,7 @@ import (
"io"
"fmt"
"os"
"os/exec"
"github.com/dotcloud/docker/pkg/dockerscript"
"github.com/dotcloud/docker/pkg/beam"
"github.com/dotcloud/docker/pkg/beam/data"
@ -182,6 +183,36 @@ func CmdTrace(args []string, f *os.File) {
}
func CmdExec(args []string, f *os.File) {
resp, err := beam.FdConn(int(f.Fd()))
if err != nil {
Fatal(err)
return
}
defer resp.Close()
cmd := exec.Command(args[1], args[2:]...)
Logf("EXEC %s %s\n", cmd.Path, cmd.Args)
stdoutR, stdoutW, err := os.Pipe()
if err != nil {
Fatal(err)
return
}
cmd.Stdout = stdoutW
stderrR, stderrW, err := os.Pipe()
if err != nil {
Fatal(err)
return
}
cmd.Stderr = stderrW
if err := beam.Send(resp, data.Empty().Set("cmd", "log", "stdout").Bytes(), stdoutR); err != nil {
Fatal(err)
}
if err := beam.Send(resp, data.Empty().Set("cmd", "log", "stderr").Bytes(), stderrR); err != nil {
Fatal(err)
}
cmd.Run()
}
func CmdLog(args []string, f *os.File) {
defer Debugf("CmdLog done\n")
var name string
@ -319,6 +350,8 @@ func builtinsHandler(args []string, attachment *os.File) {
CmdLog(args, attachment)
} else if args[0] == "trace" {
CmdTrace(args, attachment)
} else if args[0] == "exec" {
CmdExec(args, attachment)
}
}