1101 VS.NET PROCESS 输入 输出 模拟 CMD 很久以前的老文章 vs.net c# 一个调用外部程序的例子 http://www.shengfang.org/blog/p/vsnetStartInfoProcess.php Process.StandardOutput 属性 http://www.shengfang.org/blog/p/ProcessStandardOutput.php 今天看到有人回复 www.shengfang.org 有关程序中调用执行控制台应用程序并交互疑问!和楼主的文章最后一个问题相似。输入一个命令,获得输出,判断该输出内容并输入相应命令,再获得输出值...重复以上动作。 www.shengfang.org 试验了一下 要使用 StandardInput,必须已为 StartInfo 属性的 RedirectStandardInput 属性指定了 true。否则,读取 StandardInput 属性将引发异常。 注意 如果要将 StandardInput 设置为 true,则 StartInfo 属性上的 UseShellExecute 必须为 false。 www.shengfang.org ProcessStartInfo.RedirectStandardInput 属性请参见 获取或设置一个值,该值指示是否从 Process 实例的 StandardInput 成员读取进程命令输入,从而使您能够从标准输入流(通常为键盘)之外的源进行读取。例如,用于从文件读取数据。 private void DisplayOutput() www.shengfang.org { while ( proc != null && !proc.HasExited ) { string strLine = null; while ( ( strLine = proc.StandardOutput.ReadLine() ) != null) { Trace.WriteLine(strLine); m_txtOutput.AppendText( strLine + "\r\n" ); } www.shengfang.org } } www.shengfang.org Thread m_threadOutput; www.shengfang.org Process proc; www.shengfang.org private void menuItem1_Click(object sender, System.EventArgs e) { proc = new Process(); www.shengfang.org proc .StartInfo.FileName = "cmd"; proc .StartInfo.WorkingDirectory = "c:\\"; proc .StartInfo.CreateNoWindow = true; proc .StartInfo.UseShellExecute = false; proc .StartInfo.RedirectStandardOutput = true; proc .StartInfo.RedirectStandardInput = true; proc .Start(); www.shengfang.org [hide]m_threadOutput = new Thread( new ThreadStart( DisplayOutput ) ); m_threadOutput.Start(); [/hide] } www.shengfang.org private void menuItem3_Click(object sender, System.EventArgs e) { www.shengfang.org proc.StandardInput.WriteLine("dir"); } 如何在图形界面中实时捕获控制台程序的标准输出 http://www.contextfree.net/wangyg/b/tech/myide.html 和 ShellControl - A console emulation control http://www.codeproject.com/cs/miscctrl/shellcontrol.asp 1.判断命令是否执行结束并获得这个命令执行后返回的结果?(连续执行多个命令) DOTNET程序获得输出不全. 当直接执行控制台程序,在控制台中输入命令,执行完成后为出现 "XXX>"提示符等待继续输入. 由于程序采用多线程执行,本想用 "XXX>"提示符号, 来判断命令是否执行结束. 如果程序执行后,获得该命令执行得到的返内容,在执行下一命令... 但DOTNET程序却无法获得这一符号.而java写的程序却都能得到. 字体:大 中 小 |