node.jschild-process

Use child_process.execSync but keep output in console


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 output of the command and that I could print that to the console after execution, but this way I don't have "live" output.


Solution

  • 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'}
    );