#region 一个调用外部程序的例子
private static string CmdPing(string strIp)
&leftsign;
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string pingrst;
p.Start();
p.StandardInput.WriteLine("telnet 192.168.3.175 9944");
p.StandardInput.WriteLine("quit");
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
Trace.WriteLine(strRst);
p.Close();
return pingrst;
&rightsign;
#endregion
习惯改为;private static string Cmd(string strcmd)
&leftsign;
Process p = new Process();
p.StartInfo.FileName = "cmd.exe /c"+strcmd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();www.yippeesoft.com
string strRst = p.StandardOutput.ReadToEnd();
System.Diagnostics.Trace.WriteLine(strRst);
p.Close();
return strRst;
&rightsign;www.yippeesoft.com
结果:TestCase \’M:cvsaspx.CVS.test1\’ failed: 系统找不到指定的文件。www.yippeesoft.com
System.ComponentModel.Win32Exception: 系统找不到指定的文件。
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
f:\\inetpub\\wwwroot\\cvsaspx\\cvs.aspx.cs(42,0): at cvsaspx.CVS.Cmd(String strcmd)
f:\\inetpub\\wwwroot\\cvsaspx\\cvs.aspx.cs(30,0): at cvsaspx.CVS.test1()
真是失败。[hide] p.StartInfo.Arguments="/c "+strcmd; [/hide]www.yippeesoft.com
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128www.yippeesoft.com
Ping statistics for 127.0.0.1:www.yippeesoft.com
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0mswww.yippeesoft.com
历史博文
- 20080806 YippeeSoft@pick xpi - 2009
- 20071016 gui ide 可视化 - 2008
- 20070203 perl ping - 2007
- 0306 VC debug trace afxDump AfxDump 调试 - 2006
- 单片机C51复习-入门1 - 2005
- 乱七八糟猜想18门户网站19DUDU加速器病毒 - 2005
- TortoiseCVS中文帮助-取回旧版本 - 2005
- 从ASP.NET看BIN DLL所放置的目录 - 2005
- vs.net环境下开发C# asp.net时,试图运行项目时出错 - 2005