3
当我运行的git克隆像往常一样,我看到:如何将`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
然而,当我试图将其重定向到一个文件,我只看到这一点:
Cloning into 'webpack-css-example'...
这里是我的尝试:
$ git clone https://github.com/bensmithett/webpack-css-example 2>&1 | tee out.log
$ cat out.log
Cloning into 'sample-data'...
我在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'...
为什么所有的remote:
等东西没有通过管道连接到stdin/stderr?有什么方法可以捕获输出吗?如果没有,发生了什么事情使得输出显示在终端中,但它没有通过stdout或stderr传递?
有没有办法“假装”它是运行命令的终端?这样该命令可以在不改变其参数的情况下运行。这正是我所希望的,git只是一个例子。 –
@LancePollard,不是没有额外的工具,如“unbuffer”。 –
@CharlesDuffy你如何做到这一点? –