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
+
"
"
;
}
}
}
查看全文
相关阅读:
为MYSQL加注释--mysql注释符
基于SSM3框架FreeMarker自定义指令(标签)实现
SpringMVC工作原理
Web系统从Oracle迁移至MySQL
Memcached集群/分布式/高可用 及 Magent缓存代理搭建过程 详解
深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
MySQL存储引擎
mysql常用函数
转:FIFO的定义与作用
转:memset用法详解
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
并发一些概念
九大行星及希腊神话
java类加载机制
java内存区域及溢出异常
什么叫数据结构
linux设置用户自定义别名
redis-API
redis事物
unity3d开发实战《啪啪三国》技术详解!
fbx模型动画提取教程附带一个用代码提取的方法
热门文章
根据声音获取对象
判断对象是否在视线内
store下载文件保存位置
给我们的Empty Object加个图标
unity3d 移动与旋转 2
unity3d 移动与旋转 1
unity3d下载Obb分包文件
游戏美术:色彩原理
char与byte的区别
[Spring MVC]
Copyright © 2011-2022 走看看