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
+
"
"
;
}
}
}
查看全文
相关阅读:
K近邻(K Nearest Neighbor-KNN)原理讲解及实现
Bisecting KMeans (二分K均值)算法讲解及实现
KMeans (K均值)算法讲解及实现
NodeJs使用async让代码按顺序串行执行
NodeJs递归删除非空文件夹
NodeJs之配置文件管理
NodeJs针对Express框架配置Mysql进行数据库操作
在Express中使用Multiparty进行文件上传及POST、GET参数获取
Linux操作命令
SftpUtil FTP文件上传
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
架构师写给工程师的一封信(很有价值)【转】
在CentOS或RHEL防火墙上开启端口
编程语言中,取余和取模的区别到底是什么?
优化接口性能的建议
典型数据库架构设计与实践
mysql在插入或更新的时候对一个字段赋递增值
Redis设置和更新Key的过期时间
Node.js使用rabbitMQ(一)
mysql索引hash索引和b-tree索引的区别
docker的swarm介绍
热门文章
elasticsearch简介和倒排序索引介绍
elasticsearch 入门
K8S 详细介绍
K8s 介绍
关于docker容器和镜像的区别
java Timer(定时调用、实现固定时间执行)
Spring Cloud Consul
docker 安装MySQL远程连接
使用Softmax回归将神经网络输出转成概率分布
WebStrom配置SVN服务
Copyright © 2011-2022 走看看