简体   繁体   English

获取密码提示C#System.Diagnostic.Process的通知

[英]Getting notified of password prompt C# System.Diagnostic.Process

I've been trying to implement a C# wrapper around the git executable using System.Diagnostic.Process and have hit a bit of a wall. 我一直在尝试使用System.Diagnostic.Process在git可执行文件周围实现C#包装,并且遇到了一些麻烦。 What I'd like to do is when interacting with remote repositories, to pop up a password prompt in my app whenever git prompts for a username and password. 我想做的是与远程存储库进行交互时,只要git提示输入用户名和密码,我的应用程序中都会弹出一个密码提示。 This would allow the user to make use of all the built in git password credential storing tools automatically, and still have the option of inputting their credentials in the app when those are not in use. 这将允许用户自动使用所有内置的git密码凭据存储工具,并且仍可以选择在不使用凭据时在应用程序中输入其凭据。

What I've tried is the following code. 我尝试过的是以下代码。

var process = new System.Diagnostics.Process();

    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.FileName = "cmd.exe";
    process.StartInfo.Arguments = "/c git fetch";

    StringBuilder output = new StringBuilder();
    StringBuilder error = new StringBuilder();

    process.OutputDataReceived += (sender, e) =>
    {
        Debug.Log("OUTPUT DATA: " + e.Data);
    };
    process.ErrorDataReceived += (sender, e) =>
    {
        Debug.Log("ERROR DATA: " + e.Data);
    };

    process.Start();

    process.BeginOutputReadLine();
    process.BeginErrorReadLine();

    process.WaitForExit();

I see the command window pop up with "Password for: http://www.gitrepo.com " but I don't see this output in either my OutputDataReceived or ErrorDataReceived callbacks for reading by my app. 我看到带有“ Password for: http : //www.gitrepo.com ”的命令窗口弹出,但是在我的OutputDataReceived或ErrorDataReceived回调中看不到此输出,以供我的应用读取。 Ideally I'd like to trigger an event when these prompts arise and show a nice username/password dialog box for the user. 理想情况下,当这些提示出现时,我想触发一个事件,并为用户显示一个不错的用户名/密码对话框。

I dug through the git code a bit and found that these password prompts are output to and read from /dev/tty. 我仔细浏览了git代码,发现这些密码提示输出到/ dev / tty并从中读取。 Now I'm not super familiar with how input/output streams and TTYs work. 现在,我对输入/输出流和TTY的工作方式并不十分熟悉。 I'm wondering if anyone could point me in the right direction for how I might be able to detect when this prompt pops up and allow the user to pass in the 我想知道是否有人可以向我指出正确的方向,以使我能够检测到何时弹出此提示并允许用户通过

Aha. 啊哈。 I found the answer. 我找到了答案。 I can make a small little GUI application that git will prompt me with whenever it needs a password by setting "git config core.askpass 我可以制作一个小的GUI应用程序,通过设置“ git config core.askpass”,git会在需要密码时提示我

I tested with the following askpass script and it works just as needed. 我使用以下AskPass脚本进行了测试,它可以根据需要运行。

http://code.metager.de/source/xref/git/git-gui/git-gui--askpass http://code.metager.de/source/xref/git/git-gui/git-gui--askpass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是WinRT(C#)上的System.Diagnostic.Process的等价物? - What's the equivalent of the System.Diagnostic.Process on WinRT (C#)? System.Diagnostic.Process中的死锁 - Deadlock in System.Diagnostic.Process 我可以捕获用C#的System.Diagnostic.Process()启动的命令行应用程序的APPCRASH吗? - Can I catch APPCRASH of command line app launched with C#'s System.Diagnostic.Process()? 在C#中使用System.Diagnostic.Process及其UninstallString卸载程序 - Uninstall program using System.Diagnostic.Process and its UninstallString in C# 无法使用System.Diagnostic.Process运行nbtstat - Unable to run nbtstat using System.Diagnostic.Process 如何知道是否已System.Diagnostic.Process由于退出超时? - How to know if a System.Diagnostic.Process has exited due to timeout? 如何抑制使用System.Diagnostic.Process执行的exe的对话框? - How do I supress dialogs from an exe that is executed using System.Diagnostic.Process? 在c#中更改日期时间时收到通知 - Getting notified when the datetime changes in c# 如何根据C#/ WPF应用程序中外部进程退出的原因来区分System.Diagnostic.Process.Exit事件 - How to distinguish System.Diagnostic.Process.Exit events based on the reason for exit for external processes in c#/wpf applications 在C#中使用System.diagnostic打开应用程序 - opening application using System.diagnostic in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM