使用child_process.execSync,但将输出保留在控制台中 [英] Use child_process.execSync but keep output in console

查看:202
本文介绍了使用child_process.execSync,但将输出保留在控制台中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用在NodeJS 0.12中添加的 execSync 方法,但仍在运行Node脚本的控制台窗口中提供输出。



例如如果我运行具有以下行的NodeJS脚本,则希望在控制台中看到rsync命令实时的完整输出:

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

我知道 execSync 返回的输出命令,执行后可以将其打印到控制台,但是这样我就没有实时输出...

解决方案

您可以将父项的stdio传递给子进程,如果您想要什么:

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


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...

解决方案

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

这篇关于使用child_process.execSync,但将输出保留在控制台中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆