4

I'm building a custom Console interface (Windows) in C#. It simply redirect Console's standard input, output, and error to a textbox in WPF application. In the background worker, "cmd.exe" is running, and whenever it outputs anything, that output goes to textbox.

A part of the code is this

private void SetBackgroundWorker()
{
    _worker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
    _worker.DoWork += (sender, args) => ReadOutput(_worker);
    _worker.ProgressChanged += (sender, args) => _window.UpdateConsole(args);
}

private void ReadOutput(BackgroundWorker worker)
{
    int count;
    var buffer = new char[1024];
    do
    {
        var builder = new StringBuilder();
        count = _process.Read(buffer, 0, 1024);
        builder.Append(buffer, 0, count);
        worker.ReportProgress(0, builder.ToString());

    } while (count > 0);
}

Then, I can do "git add", "git status", or "git commit" commands within this interface (I added the path to git bin directory in PATH), but when I try "git push origin master", the textbox is not updated. I would expect "Username for '...'" and "Password for '...'", but it never happens.

When I do "git push..." in command prompt, it display them, but in my wpf interface, "cmd.exe" doesn't seem to redirect the output at all, and I'm lost here

One thing I thought I could try was to give up with Redirection, and use Windows api to hook cmd.exe, but it wouild be more complicated.

If you could advise me, I would really appreciate it.

If you want to look at the full code and test it, the code is in https://github.com/andrewchaa/ConsolePlus. It's in a very primitive stage.

4

2 に答える 2

3

アプリケーションは、画面バッファに直接書き込むWriteConsoleのようなものを使用していると思います。特に標準出力/標準エラーのリダイレクトでは、それを傍受する方法はありません。git アプリケーションが何をしているのか、具体的にはわかりません。ただし、色を頻繁に使用するため、画面メモリを直接処理するSetConsoleTextAttributeなどの関数を使用する必要があるようです。

于 2012-09-11T17:42:22.903 に答える