Skip to content

Commit 2cd8af5

Browse files
Sahin VardarSahin Vardar
authored andcommitted
Added the ability to stream 'stdout' and 'stderr' from docker command.
For long running docker commands, it is quite convinient to stream stdout and stderr from the child process to the host process. Otherwise you are only able get and display the result of the stream, after docker.command was executed.
1 parent 78c724a commit 2cd8af5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class Docker {
208208
//console.log('execCommand =', execCommand);
209209
//console.log('exec options =', execOptions);
210210

211-
exec(execCommand, execOptions, function(error, stdout, stderr) {
211+
const childProcess = exec(execCommand, execOptions, function(error, stdout, stderr) {
212212
if (error) {
213213
const message = `error: '${error}' stdout = '${stdout}' stderr = '${stderr}'`;
214214
reject(message);
@@ -217,6 +217,15 @@ export class Docker {
217217
//doesn't work otherwise for 'build - t nginximg1 .'
218218
resolve({ result: stdout});
219219
});
220+
221+
childProcess.stdout.on("data", (chunk) => {
222+
process.stdout.write( chunk.toString() );
223+
});
224+
225+
childProcess.stderr.on("data", (chunk) => {
226+
process.stderr.write( chunk.toString() );
227+
});
228+
220229
});
221230
}).then(function(data: any) {
222231
//console.log('data:', data);

0 commit comments

Comments
 (0)