1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Return the process exit code for run commands

This commit is contained in:
Michael Crosby 2013-09-05 23:54:03 +00:00
parent 3a6868bc2f
commit 3bc73fa21e

View file

@ -367,16 +367,11 @@ func (cli *DockerCli) CmdWait(args ...string) error {
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
body, _, err := cli.call("POST", "/containers/"+name+"/wait", nil) status, err := waitForExit(cli, name)
if err != nil { if err != nil {
fmt.Fprintf(cli.err, "%s", err) fmt.Fprintf(cli.err, "%s", err)
} else { } else {
var out APIWait fmt.Fprintf(cli.out, "%d\n", status)
err = json.Unmarshal(body, &out)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%d\n", out.StatusCode)
} }
} }
return nil return nil
@ -1477,8 +1472,16 @@ func (cli *DockerCli) CmdRun(args ...string) error {
} }
if !config.AttachStdout && !config.AttachStderr { if !config.AttachStdout && !config.AttachStderr {
// Detached mode
<-wait <-wait
} else {
status, err := waitForExit(cli, runResult.ID)
if err != nil {
return err
} }
os.Exit(status)
}
return nil return nil
} }
@ -1759,6 +1762,19 @@ func (cli *DockerCli) LoadConfigFile() (err error) {
return err return err
} }
func waitForExit(cli *DockerCli, containerId string) (int, error) {
body, _, err := cli.call("POST", "/containers/"+containerId+"/wait", nil)
if err != nil {
return -1, err
}
var out APIWait
if err := json.Unmarshal(body, &out); err != nil {
return -1, err
}
return out.StatusCode, nil
}
func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string) *DockerCli { func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string) *DockerCli {
var ( var (
isTerminal = false isTerminal = false