简体   繁体   English

生成`git clone`后将输出流式传输到标准输出

[英]Stream output to stdout after spawning `git clone`

I'm just trying to run git clone from node and stream the output into stdout just like running from shell normally would, but after using child_process.spawn , I can't get the output to pipe into stdout.我只是想从节点运行git clone并将输出流式传输到标准输出,就像通常从 shell 运行一样,但是在使用child_process.spawn ,我无法将输出通过管道传输到标准输出。 Currently I'm using:目前我正在使用:

child = spawn('git', ['clone', url]);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);

But I only see "Cloning into 'directory'" message and not the remote messages and "Receiving objects...".但我只看到“克隆到‘目录’”消息,而不是远程消息和“接收对象...”。

What am I doing wrong?我究竟做错了什么?

By default, git clone only shows progress when it's running in a terminal.默认情况下, git clone仅在终端中运行时显示进度。 When it's not running in a terminal progress can be enabled with the --progress argument :当它不在终端中运行时,可以使用--progress参数启用:

Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified.除非指定了 -q,否则在连接到终端时,默认情况下会在标准错误流上报告进度状态。 This flag forces progress status even if the standard error stream is not directed to a terminal.即使标准错误流未定向到终端,此标志也会强制进度状态。

However I'm not sure that that will do exactly what you expect.但是,我不确定这会完全符合您的期望。 The progress output isn't simple output;进度输出不是简单的输出; values change in place.价值观发生了变化。 I'm not exactly sure how nicely that will play with child_process.spawn() .我不确定这会与child_process.spawn()一起child_process.spawn()有多好。

Note also that output is to STDERR , not STDOUT .还要注意输出是到STDERR ,而不是STDOUT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM