Use child_process.execSync but keep output in console

suamikim picture suamikim · May 9, 2015 · Viewed 108k times · Source

I'd like to use the execSync method which was added in NodeJS 0.12 but still have the output in the console window from which i ran the Node script.

E.g. if I run a NodeJS script which has the following line I'd like to see the full output of the rsync command "live" inside the console:

require('child_process').execSync('rsync -avAXz --info=progress2 "/src" "/dest"');

I understand that execSync returns the ouput of the command and that I could print that to the console after execution but this way I don't have "live" output...

Answer

gregers picture gregers · Jun 28, 2015

You can pass the parent´s stdio to the child process if that´s what you want:

require('child_process').execSync(
    'rsync -avAXz --info=progress2 "/src" "/dest"',
    {stdio: 'inherit'}
);