Lan*_*ard 6 unix git shell pipe
当我像往常一样运行git clone时,我看到了:
$ git clone https://github.com/bensmithett/webpack-css-example
Cloning into 'webpack-css-example'...
remote: Counting objects: 179, done.
remote: Total 179 (delta 0), reused 0 (delta 0), pack-reused 179
Receiving objects: 100% (179/179), 24.07 KiB | 0 bytes/s, done.
Resolving deltas: 100% (79/79), done.
Checking connectivity... done
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将其重定向到文件时,我只看到这个:
Cloning into 'webpack-css-example'...
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
$ git clone https://github.com/bensmithett/webpack-css-example 2>&1 | tee out.log
$ cat out.log
Cloning into 'sample-data'...
Run Code Online (Sandbox Code Playgroud)
我也在Node.js中尝试过它,它做了同样的事情:
const fs = require('fs');
const child = spawn('git clone https://github.com/bensmithett/webpack-css-example');
child.stdout.on('data', function(data){
console.log(String(data));
});
child.stderr.on('data', function(data){
console.log(String(data));
});
// Cloning into 'webpack-css-example'...
Run Code Online (Sandbox Code Playgroud)
为什么所有remote:
等等东西都没有被管道传输到stdin/stderr?有没有办法捕获输出?如果没有,发生了什么使得输出显示在终端中,但是它没有通过stdout或stderr传递?
默认情况下,只有当标准错误流定向到终端时,Git才会显示克隆进度.由于您将其重定向到管道,因此输出流不再连接到终端.因此,为了捕获输出,您需要添加--progress
参数以强制进度状态,例如
git clone --progress https://github.com/foo/bar 2> out.log
Run Code Online (Sandbox Code Playgroud)
看到: man git-clone
--progress
除非已指定,否则在连接到终端时,默认情况下会在标准错误流上报告进度状态
-q
.即使标准错误流未定向到终端,此标志也会强制进度状态.
要以任何其他方式强制终端,您必须预加载一些库以强制isatty()
返回始终为true(请参阅:) man isatty
.git在源代码中使用此函数.
归档时间: |
|
查看次数: |
4752 次 |
最近记录: |