c#中重定向windows控制台程序的输出信息 - jinjazz - CSDNBlog
2008-05-17 16:30
627 查看
导读:
这个问题来自论坛提问,答案如下.这只是一个简单的ipconfig命令.如果是复杂的,比如oracle的exp之类的命令,能在调用的时候显示出来,还是相当酷的.
using System;
using System.Windows.Forms;
namespace WindowsApplication8
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
delegate void dReadLine(string strLine);
private void excuteCommand(string strFile, string args, dReadLine onReadLine)
...{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo();
p.StartInfo.FileName = strFile;
p.StartInfo.Arguments = args;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
System.IO.StreamReader reader = p.StandardOutput;//截取输出流
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)
...{
onReadLine(line);
line = reader.ReadLine();
}
p.WaitForExit();
}
private void button1_Click(object sender, EventArgs e)
...{
excuteCommand("ipconfig", "", new dReadLine(PrintMessage));
}
private
本文转自
http://blog.csdn.net/jinjazz/archive/2008/05/07/2413039.aspx
这个问题来自论坛提问,答案如下.这只是一个简单的ipconfig命令.如果是复杂的,比如oracle的exp之类的命令,能在调用的时候显示出来,还是相当酷的.
using System;
using System.Windows.Forms;
namespace WindowsApplication8
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
delegate void dReadLine(string strLine);
private void excuteCommand(string strFile, string args, dReadLine onReadLine)
...{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo();
p.StartInfo.FileName = strFile;
p.StartInfo.Arguments = args;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
System.IO.StreamReader reader = p.StandardOutput;//截取输出流
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)
...{
onReadLine(line);
line = reader.ReadLine();
}
p.WaitForExit();
}
private void button1_Click(object sender, EventArgs e)
...{
excuteCommand("ipconfig", "", new dReadLine(PrintMessage));
}
private
本文转自
http://blog.csdn.net/jinjazz/archive/2008/05/07/2413039.aspx
相关文章推荐
- c#中重定向windows控制台程序的输出信息
- c#中重定向windows控制台程序的输出信息
- c#中重定向windows控制台程序的输出信息
- c#中重定向windows控制台程序的输出信息
- c#中重定向windows控制台程序的输出信息
- c#中重定向windows控制台程序的输出信息
- c#中重定向windows控制台程序的输出信息
- C# 窗体程序,使用控制台输出调试信息
- Windows进程内标准输出重定向及其在程序调试上的应用
- [Windows]_[中级]_[界面程序打开控制台输出-转发输出到控制台]
- c# 调用控制台程序并传参 获取控制台输出(解释器的前台处理)
- VS2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- 用qDebug调试输出QT控制台程序(windows)
- 调试程序时在不中断程序的情况下输出函数调用信息(Mac OS,Linux & Windows)
- Java程序将输出到控制台的语句存入文件和windows DOS将文字输入到文件中
- C# form程序读取console 程序的控制台信息
- 在MFC,Win32程序中向控制台(Console)窗口输出调试信息
- C# 小程序之新手练习(一)控制台动态输出当前时间
- Createprocess控制台程序输出重定向
- C#控制台----第三方程序控制台输出的隐藏