【发布时间】:2011-11-23 01:21:53
【问题描述】:
使用此代码,我看到登录窗口提示输入密码,但我似乎无法将密码写入 shell 窗口。
Process scp = new Process();
scp.StartInfo.FileName = @"c:\cygwin\bin\scp";
scp.StartInfo.Arguments = "/cygdrive/c" + path + " " + username + "@" + ServerName + ":/cygdrive/c/Temp/.";
scp.StartInfo.UseShellExecute = false;
scp.StartInfo.RedirectStandardOutput = true;
scp.StartInfo.RedirectStandardError = true;
scp.StartInfo.RedirectStandardInput = true;
scp.Start();
//I've tried this with no success:
using (StreamWriter sw = scp.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(pass);
}
}
// Another failed attempt:
scp.StandardInput.Write(pass + Environment.NewLine);
scp.StandardInput.Flush();
Thread.Sleep(1000);
我知道我可以让它与 cygwin expect 一起工作,但宁愿使用 c# 与 windows 输入/输出交互。
【问题讨论】: