string un = "weipan";
string pw = "weipan"; string ssh_mach = "plink -ssh 118.88.128.133 -l r -pw r";
//创建用户并设置密码
//sudo useradd -d /home/r -s /bin/bash -m r
//sudo su root -c 'echo "r:r" | chpasswd'
string add_user = "sudo useradd -d /home/" + un + " -s /bin/bash -m " + un;
string add_pass = "sudo su root -c 'echo \"" + un + ":" + pw + "\" | chpasswd'"; string binStr = System.Web.Hosting.HostingEnvironment.MapPath("~/plink.exe");
System.Diagnostics.Process exep = new System.Diagnostics.Process();
exep.StartInfo.FileName = binStr; //FileName 可执行程序文件名
//exep.StartInfo.Arguments = cmdStr; //Arguments 程序参数,以字符串形式输入
exep.StartInfo.CreateNoWindow = true; //CreateNoWindow 是否不需要创建窗口
exep.StartInfo.UseShellExecute = false; //UseShellExecute 是否需要系统shell调用程序
//pro.StartInfo.RedirectStandardInput = true;
exep.StartInfo.RedirectStandardInput = true;
exep.StartInfo.RedirectStandardOutput = true;
exep.StartInfo.Arguments = ssh_mach;
exep.Start();
exep.StandardInput.WriteLine(ssh_mach);
exep.StandardInput.Flush();
exep.StandardInput.WriteLine(add_user);
exep.StandardInput.Flush();
//exep.StandardInput.WriteLine("exit");
exep.StandardInput.WriteLine(add_pass);
exep.StandardInput.Flush(); TextBox1.Text = exep.StandardOutput.ReadToEnd().ToString();
//exep.StandardOutput.Read();
//exep.Exited
exep.WaitForExit();//关键,等待外部程序退出后才能往下执行
exep.Close();以上是我的代码,我想调用plink.exe(用来连接linux机器操作一些linux命令)这个文件,然后连接到linux机器上,调用一些命令,现在能连接到linxu机器上,但是无法执行linxu命令
PS:我这个东西做完需要放到linux机器上,所以请不要告诉我调用cmd.exe的方法!
解决方案 »
- winform datagridview 当用户在单元格中输入数据的时候(正在输入中的时候),触发什么事件,怎么在取得现在已输入的值?
- c#及时获得数据库更新信息
- 在C# 如何使用 activeskin 皮肤控件!小弟初学C#,请问应该看哪些书或资料,与VC6.0基础
- 新手问个简单问题
- 关于static的问题
- 初学者提问:从数据集dataSet插入记录更新数据库,出了问题,大家帮忙看一下
- 初级问题,如何实现,按下一button后,向TextBox的当前光标处输入一个字符串“hello”。
- 请教大数据量的问题
- 如何取得当前窗口的分辨率?
- 使用Microsoft.Office.Interop.Excel.Application导出excel时提示“请求的操作需要提升”
- 用DEV的 下拉列表类控件报错
- 急!!!!!!
http://social.msdn.microsoft.com/Forums/zh-CN/csharpgeneral/thread/c14d5871-28c9-4bfc-a56d-d3d3a50395f4 ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.Arguments = "-ssh username@" + su + " -pw passwd";
pInfo.FileName = Server.MapPath("~/plink.exe");
Process p = new Process();
p.StartInfo = pInfo;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start(); StreamWriter myStreamWriter = p.StandardInput;
myStreamWriter.WriteLine("sudo useradd -d /home/wp -s /bin/bash -m wp");
myStreamWriter.WriteLine("sudo su root -c 'echo \"wp:wp\" | chpasswd'");
myStreamWriter.WriteLine("exit");
StreamReader ss = p.StandardOutput; pand = ss.ReadLine().ToString();
p.StandardInput.Flush();
p.WaitForExit();
p.Close();