将密码流传递给流程标准输入(C#)

将密码流传递给流程标准输入(C#),c#,process,passwords,stdin,C#,Process,Passwords,Stdin,上述代码将应答发送到作为System.Diagnostics.Process启动的命令行实用程序 在我通过密码之前,一切正常。这就是程序无限期停止的地方——就像StreamWriter WriteLine拒绝工作一样:没有任何错误。 当我手动启动实用程序时,密码在我键入时不会显示(显然)。我怀疑这就是导致实用程序无法“感知”密码流传递的原因。 有什么想法吗 (另一方面,该实用程序允许将答案作为管道文件传递,但该过程不喜欢管道字符作为参数“以下解决了我的问题。谢谢 class MyProcess

上述代码将应答发送到作为System.Diagnostics.Process启动的命令行实用程序

在我通过密码之前,一切正常。这就是程序无限期停止的地方——就像StreamWriter WriteLine拒绝工作一样:没有任何错误。 当我手动启动实用程序时,密码在我键入时不会显示(显然)。我怀疑这就是导致实用程序无法“感知”密码流传递的原因。 有什么想法吗

(另一方面,该实用程序允许将答案作为管道文件传递,但该过程不喜欢管道字符作为参数“以下解决了我的问题。谢谢
class MyProcess : Process {
//this is where all the StartInfo parameters are set
}        
MyProcess connectProc = new MyProcess();
connectProc.Start();
        
        int BuffSize = 64 * 1024;
        Char[] x = new Char[BuffSize];
        int bytesRead = 0;
        System.Threading.Thread.Sleep(1000);
    //reads the initial text until the first question
        singleResponse = "";
        bytesRead = connectProc.StandardOutput.Read(x, 0, BuffSize);
        singleResponse = String.Concat(singleResponse, String.Join("", x).Substring(0, bytesRead));
        
        //prepares the answer streamwriter
        connectProc.myStreamWriter = connectProc.StandardInput;
        
        //the answers list
        string[] answers = {"y","1","myusername","mypassword","y" };
        
        //cycles through the answers
        foreach (string ans in answers)
        {
           connectProc.myStreamWriter.WriteLine(ans);
           System.Threading.Thread.Sleep(1000);
           singleResponse = "";
           bytesRead = connectProc.StandardOutput.Read(x, 0, BuffSize);
           singleResponse = String.Concat(singleResponse, String.Join("", x).Substring(0, bytesRead));
        }