首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(1) | 引用(1) | 阅读5144次
vs.net c# 一个调用外部程序的例子

#region 一个调用外部程序的例子
  private static string CmdPing(string strIp)
  {
   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;
   }
#endregion

习惯改为;private static string Cmd(string strcmd)
{
 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.shengfang.org
 string strRst = p.StandardOutput.ReadToEnd();
 System.Diagnostics.Trace.WriteLine(strRst);
 p.Close();
 return strRst;
}www.shengfang.org

结果:TestCase 'M:cvsaspx.CVS.test1' failed: 系统找不到指定的文件。www.shengfang.org
 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.shengfang.org

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.shengfang.org

Ping statistics for 127.0.0.1:www.shengfang.org
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0mswww.shengfang.org


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/vsnetStartInfoProcess.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1120721210

2005年7月7日15:26星期四  [Dev开发] 追踪此文的RSS
路过在 2007年12月15日23:40星期六 评论:

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1839
在线: 15||用户: 2576 [列表]
今日:2276||到访:2854130
Rss:885231||评论:1604

最新日志

最新评论

友情链接

日历

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8