@@ -539,18 +539,27 @@ func inspectCommandExitCode(ctx context.Context, dockerClient *client.Client, co
539539 return errors .Errorf ("exit code: %d" , inspect .ExitCode )
540540}
541541
542- // ExecCommandWithOutput runs command in Docker container and returns the command output.
542+ // ExecCommandWithOutput runs command in Docker container, enables all stdout and stderr and returns the command output.
543543func ExecCommandWithOutput (ctx context.Context , dockerClient * client.Client , containerID string , execCfg types.ExecConfig ) (string , error ) {
544544 execCfg .AttachStdout = true
545545 execCfg .AttachStderr = true
546546
547- execCommand , err := dockerClient .ContainerExecCreate (ctx , containerID , execCfg )
547+ return execCommandWithResponse (ctx , dockerClient , containerID , execCfg )
548+ }
549+
550+ // ExecCommandWithResponse runs command in Docker container and returns the command output.
551+ func ExecCommandWithResponse (ctx context.Context , docker * client.Client , containerID string , execCfg types.ExecConfig ) (string , error ) {
552+ return execCommandWithResponse (ctx , docker , containerID , execCfg )
553+ }
554+
555+ func execCommandWithResponse (ctx context.Context , docker * client.Client , containerID string , execCfg types.ExecConfig ) (string , error ) {
556+ execCommand , err := docker .ContainerExecCreate (ctx , containerID , execCfg )
548557
549558 if err != nil {
550559 return "" , errors .Wrap (err , "failed to create an exec command" )
551560 }
552561
553- attachResponse , err := dockerClient .ContainerExecAttach (ctx , execCommand .ID , types.ExecStartCheck {})
562+ attachResponse , err := docker .ContainerExecAttach (ctx , execCommand .ID , types.ExecStartCheck {})
554563 if err != nil {
555564 return "" , errors .Wrap (err , "failed to attach to exec command" )
556565 }
@@ -562,7 +571,7 @@ func ExecCommandWithOutput(ctx context.Context, dockerClient *client.Client, con
562571 return string (output ), errors .Wrap (err , "failed to read response of exec command" )
563572 }
564573
565- inspection , err := dockerClient .ContainerExecInspect (ctx , execCommand .ID )
574+ inspection , err := docker .ContainerExecInspect (ctx , execCommand .ID )
566575 if err != nil {
567576 return "" , fmt .Errorf ("failed to inspect an exec process: %w" , err )
568577 }
@@ -599,7 +608,7 @@ func processAttachResponse(ctx context.Context, reader io.Reader) ([]byte, error
599608 }
600609
601610 if errBuf .Len () > 0 {
602- return nil , errors . New (errBuf .String ())
611+ log . Dbg (errBuf .String ())
603612 }
604613
605614 return bytes .TrimSpace (outBuf .Bytes ()), nil
0 commit comments