我只是想从 Node 运行 git clone
并将输出流式传输到标准输出,就像通常从 shell 运行一样,但是在使用 child_process.spawn
之后,我无法将输出通过管道传输到标准输出。目前我正在使用:
child = spawn('git', ['clone', url]);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
但我只看到“克隆到‘目录’”消息,而不是远程消息和“正在接收对象...”。
我做错了什么?
最佳答案
默认情况下,git clone
仅在终端中运行时显示进度。当它不在终端中运行时,可以使用 --progress
argument 启用进度:
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.
但是我不确定这是否会完全符合您的期望。进度输出不是简单的输出;值改变到位。我不太确定它与 child_process.spawn()
的配合有多好。
另请注意,输出是STDERR
,而不是STDOUT
。
关于javascript - 生成 `git clone` 后将输出流式传输到标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51956300/