Wednesday, 24 May 2017

Node.js Spawn Display STDOUT live not working

I have an app it receives file links and downloads them, for downloading I am used aria2c.

For doing this first I used exec, but since I want to get download progress then I used spawn

Here is code i am using for download file with aria2c:

'use strict';

const
    spawn = require( 'child_process' ).spawn,
    aria2c = spawn( 'aria2c', ['-x8', 'https://wa-us-ping.vultr.com/vultr.com.100MB.bin' ] );

aria2c.stdout.on( 'data', data => {
    console.log( `stdout: ${data}` );
});

aria2c.stderr.on( 'data', data => {
    console.log( `stderr: ${data}` );
});

aria2c.on( 'close', code => {
    console.log( `child process exited with code ${code}` );
});

When I run this code it doesn't print aria2c output to stdout, it only shows it when download finished.

I want to know how I can fix this.



via user1086010

No comments:

Post a Comment