0
我想從一個git進程輸出到另一個git命令的輸入。但我無法工作。 Git版本1.9.5.msysgit.0MSysGit管道編碼
我想代碼做什麼:
git show e46b22be3031ed53e80472002d332a2588f122c9 | git patch-id
Output:
c2a55fcbc40da401f84ae3b72c250e55f827001a e46b22be3031ed53e80472002d332a2588f122c9
我的管道輸出到一個文件,這樣我有一些與進行比較:
git show e46b22be3031ed53e80472002d332a2588f122c9 > git.show.txt
重定向從所述文件的輸入產生了預期的結果:
git patch-id < commit.show.txt
Output:
c2a55fcbc40da401f84ae3b72c250e55f827001a e46b22be3031ed53e80472002d332a2588f122c9
對HEL p我解決問題,我寫了一個代理應用程序:
- 讀取混帳顯示管道輸入
- 管道輸入寫入一個文件,這樣我就可以用git.show.txt 進行比較
- 管道輸入寫入到輸出,使下一個應用程序可以把它管道
所以使用現在是:
git show e46b22be3031ed53e80472002d332a2588f122c9 | ConsolePipeConsumer.exe | git patch-id
Incorrect Output:
cf55b48fa7c9ed6f7214641c4d709667abfeb078 e46b22be3031ed53e80472002d332a2588f122c9
我寫的臨時文件是二進制文件,等於git.show.txt,因此讀取輸入的方式如預期的那樣工作。
我只是無法弄清楚代理頁面用於我的代理應用程序的標準輸出。我嘗試了所有我能想到的。還是有其他缺失?
下面的代碼:
using System;
using System.IO;
using System.Text;
namespace ConsolePipeConsumer
{
class Program
{
static void Main(string[] args)
{
try
{
var encoding = Encoding.Default;
Console.SetIn(new StreamReader(Console.OpenStandardInput(8192), encoding));
Console.Error.WriteLine("StdOut.Encoding={0}", Console.Out.Encoding);
// What encoding to use for output?
//Console.SetOut(new StreamWriter(Console.OpenStandardOutput(8192), encoding));
int c;
var sb = new StringBuilder();
while ((c = Console.Read()) >= 0)
{
sb.Append((char)c);
}
Console.Write(sb.ToString());
var tmp = Path.GetTempFileName();
File.WriteAllText(tmp, sb.ToString(), encoding);
Console.Error.WriteLine("Piped input written to: " + tmp);
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.ToString());
}
}
}
}
我可能將要發生什麼。我將ConsolePipeConsumer的輸出傳送給另一個ConsolePipeConsumer實例,並注意數據被截斷。 – careri
這是很不明確的你問,你似乎正在重寫'tee' – edi9999
你爲什麼讀寫字符*,並試圖擔心編碼?如果目的不是*改變*編碼,那麼你應該可以讀寫*字節*。 –