mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
split stdout and stderr in run if not -t
This commit is contained in:
parent
a5fe6f8af4
commit
e33ba9b36d
1 changed files with 20 additions and 15 deletions
35
commands.go
35
commands.go
|
@ -1016,29 +1016,32 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
splitStderr := container.Config.Tty
|
||||
|
||||
connections := 1
|
||||
if !container.Config.Tty {
|
||||
if splitStderr {
|
||||
connections += 1
|
||||
}
|
||||
c := make(chan error, 2)
|
||||
chErrors := make(chan error, connections)
|
||||
cli.monitorTtySize(cmd.Arg(0))
|
||||
if !container.Config.Tty {
|
||||
if splitStderr {
|
||||
go func() {
|
||||
c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr)
|
||||
chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr)
|
||||
}()
|
||||
}
|
||||
v := url.Values{}
|
||||
v.Set("stream", "1")
|
||||
v.Set("stdin", "1")
|
||||
v.Set("stdout", "1")
|
||||
if container.Config.Tty {
|
||||
if !splitStderr {
|
||||
v.Set("stderr", "1")
|
||||
}
|
||||
go func() {
|
||||
c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout)
|
||||
chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout)
|
||||
}()
|
||||
for connections > 0 {
|
||||
err := <-c
|
||||
err := <-chErrors
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1206,11 +1209,13 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
fmt.Fprintln(os.Stderr, "WARNING: ", warning)
|
||||
}
|
||||
|
||||
splitStderr := !config.Tty
|
||||
|
||||
connections := 0
|
||||
if config.AttachStdin || config.AttachStdout {
|
||||
if config.AttachStdin || config.AttachStdout || (!splitStderr && config.AttachStderr) {
|
||||
connections += 1
|
||||
}
|
||||
if !config.Tty && config.AttachStderr {
|
||||
if splitStderr && config.AttachStderr {
|
||||
connections += 1
|
||||
}
|
||||
|
||||
|
@ -1221,12 +1226,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
}
|
||||
|
||||
if connections > 0 {
|
||||
c := make(chan error, connections)
|
||||
chErrors := make(chan error, connections)
|
||||
cli.monitorTtySize(out.Id)
|
||||
|
||||
if !config.Tty && config.AttachStderr {
|
||||
if splitStderr && config.AttachStderr {
|
||||
go func() {
|
||||
c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr)
|
||||
chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr)
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -1240,14 +1245,14 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
if config.AttachStdout {
|
||||
v.Set("stdout", "1")
|
||||
}
|
||||
if config.Tty && config.AttachStderr {
|
||||
if !splitStderr && config.AttachStderr {
|
||||
v.Set("stderr", "1")
|
||||
}
|
||||
go func() {
|
||||
c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout)
|
||||
chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout)
|
||||
}()
|
||||
for connections > 0 {
|
||||
err := <-c
|
||||
err := <-chErrors
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue