3
3
from ..api import APIClient
4
4
from ..errors import (ContainerError , ImageNotFound ,
5
5
create_unexpected_kwargs_error )
6
- from ..types import HostConfig
6
+ from ..types import ExecResult , HostConfig
7
7
from ..utils import version_gte
8
8
from .images import Image
9
9
from .resource import Collection , Model
@@ -150,9 +150,10 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
150
150
workdir (str): Path to working directory for this exec session
151
151
152
152
Returns:
153
- (tuple ): A tuple of (exit_code, output)
153
+ (ExecResult ): A tuple of (exit_code, output)
154
154
exit_code: (int):
155
- Exit code for the executed command
155
+ Exit code for the executed command or ``None`` if
156
+ either ``stream```or ``socket`` is ``True``.
156
157
output: (generator or str):
157
158
If ``stream=True``, a generator yielding response chunks.
158
159
If ``socket=True``, a socket object for the connection.
@@ -170,10 +171,12 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
170
171
exec_output = self .client .api .exec_start (
171
172
resp ['Id' ], detach = detach , tty = tty , stream = stream , socket = socket
172
173
)
173
- exit_code = 0
174
- if stream is False :
175
- exit_code = self .client .api .exec_inspect (resp ['Id' ])['ExitCode' ]
176
- return (exit_code , exec_output )
174
+ if socket or stream :
175
+ return ExecResult (None , exec_output )
176
+ else :
177
+ return ExecResult (
178
+ self .client .api .exec_inspect (resp ['Id' ])['ExitCode' ],
179
+ exec_output )
177
180
178
181
def export (self ):
179
182
"""
0 commit comments