zoukankan
html css js c++ java
c#中重定向windows控制台程序的输出信息
这个问题来自论坛提问,答案如下.这只是一个简单的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
void
PrintMessage(
string
strLine)
...
{
this
.textBox1.Text
+=
strLine
+
"
"
;
}
}
}
查看全文
相关阅读:
011-iOS核心动画(Core Animation)
010-CALayer(图层)
009-手势触摸事件处理
008-Quartz2D
007-多控制器管理及其控制器间的数据传递
007-多控制器管理(控制器间的数据传递)
通过底层 socket 监控 http/https 思路
NDK 线程同步
时间同步算法探究
Android 事件小结
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
2014-03-24
2014-03-18
2014-03-20
effective c++读书随记
Let's make TCP faster
数组元素最小差
const in c and cpp
solarized for securecrt
提取字符串中引号中内容
在构造函数和析构函数中调用虚函数
热门文章
对数组取地址
Curiously recurring template pattern
为什么const修饰参数不算重载
为什么不能分开模板的声明和定义,把定义放到.cpp文件中?
java链接oracle数据库
mybatis的DOCTYPE当eclipse不能联网是卡顿问题
iOS9-01新增特性之UIStackView
ios之过滤器,排序器
013-一些开发小技巧
012-iOS之多线程管理
Copyright © 2011-2022 走看看