控制台cmd,程序输入一段命令之后,要求输入密码。请问能否让程序自动输入,不要人工手动输入。
急,请帮忙!
急,请帮忙!
解决方案 »
- wcf 操作即将死锁
- price的排序
- C#异常处理
- panel1有滚动条 在panel1里有好多textbox控件把滚动条拉到下端 点下端的textbox 可滚动条又回到了最上端
- C#制作的安装程序,如何在自定义操作中获取安装的目的路径?
- 请问如何获取服务器端的时间和本机的ip地址啊?
- [高手赐教]如何自定义一事件,并带有自己的参数。
- 菜鸟请教如何实现动态的tabpage?每个page里面有多个checkedListBox,radioButton,textBox和一个控制page数量的numericUpDown?
- 高手请进,如何实现两个树控件节点之间的画线,在线等待,急!!!谢谢了
- C#中的Regex.Replace的问题
- VS3.5怎么才能转成VS2.0
- visual stduio 2010好用吗?有必要升级吗?
start.Arguments = "[email protected] 'mkdir .sshtest;chmod 0700 .sshtest'\r";//设置命令参数
start.CreateNoWindow = false;//不显示dos命令行窗口
start.RedirectStandardOutput = true;//
start.RedirectStandardInput = true;//
start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
Process p = Process.Start(start);这之后怎么做?程序自动输入密码!
要看这个程序怎么传参吧
input your's password:这个地方我不知道怎么去让程序输入password,然后让它执行。
ssh没有带密码的参数命令,只有上面一条执行之后,然后再输入密码。
保存为一个文本 在执行 ssh < 保存的文本试试
ftp可以这么做
这个方法我也试了,但还是没有成功。
StreamWriter sw = p.StandardInput;
sw.WriteLine("password\r");
password是正确的,\r去掉的结果是一样的。
http://topic.csdn.net/u/20091017/01/14ecfe58-80f4-4d1c-87e1-14038f9ddd4b.html其实对于Process类,主要可以控制的就是StreamWriter input = p.StandardInput;
StreamReader output = p.StandardOutput;
StreamReader error = p.StandardError;其中作为输出的包括两个,StandardOutput和StandardError,作为输入的只有1个StandardInput
再输入password才行!
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.CreateNoWindow = false;//不显示dos命令行窗口
p.StartInfo.RedirectStandardOutput = true;//
p.StartInfo.RedirectStandardInput = true;//
// p.StartInfo.UseShellExecute = true;
p.StandardInput.AutoFlush = true;
StreamWriter sw = p.StandardInput;
sw.WriteLine("ssh [email protected] 'mkdir .sshtest;chmod 0700 .sshtest'\r");
while (true)
{
if (p.StandardOutput.ReadLine() == "input your's password:")
{
sw.WriteLine("password");
break;
}
}这样对么?p.StandardOutput.ReadLine()貌似没得到我要的“input your's password:”,但是控制台上是显示了这句话的。
dos 重定向
或者
DOS 输入 重定向
/// 将程序重新启动
/// </summary>
/// <param name="appName">程序的名称</param>
/// <param name="filepath">程序的路径</param>
/// <param name="admin">管理员名称</param>
/// <param name="password">管理员密码</param>
/// <param name="domain">域名称</param>
/// <returns>是否已经启动</returns>
public static bool IsReStartApp(string appName,string filepath,string admin,string password,string domain)
{
appName = appName.ToUpper();
if (IsAppExist(appName))
return true;
SecureString ses = new SecureString();
foreach (char c in password)
{
ses.AppendChar(c);
} Process.Start(filepath, admin, ses, domain);
return true;
}
(估计LZ所说的SSH跟这个情况是相同的)LZ可以看看ssh有没有命令行参数支持直接输入用户名和密码,
或像ftp一样,支持 ftp -s:a.txt(将a.txt里的内容作为input内容),如果还有问题的话,
试试通过获得窗口句柄,向里面发送键盘消息的方法。