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
+
"
"
;
}
}
}
查看全文
相关阅读:
CDH Mysql元数据库升级
greenplum gpcheckperf 命令(GP集群压力测试)
centos7 升级openssh到openssh-8.0p1版本(转)
正则表达式中的 1
Docker系列03—Docker 基础入门
Docker系列01—容器的发展历程
二进制安装部署 4 kubernetes集群---超详细教程
kubernetes系列11—PV和PVC详解
kubernetes系列10—存储卷详解
kubernetes系列09—Ingress控制器详解
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
Nginx(四)-- Nginx的扩展-OpenRestry
Nginx(三)--Nginx 的高可用
测试界大牛博客
Locust学习总结分享
ZooKeeper服务命令:
Zookeeper集群搭建
WEB 端批量移动设备管理控制工具 STF 的环境搭建和运行
jmeter接口参数化获取tocken后保存批量保存在本地
centos7.4版本安装nmon监控软件
springboot配置文件启动顺序
热门文章
正则 常用
redis基础
正则 字典表
@EnableConfigurationProperties、@EnableAsync、 @EnableTransactionManagement
for循环相关
mysql 【常用sql】
mysql 开启binlog
MySQL系列-优化之like关键字 创建索引
mysql 常用函数-locate 和 instr POSITION、FIND_IN_SET 和 regexp
Cloudera-Manager安装意外中断如何卸载的问题
Copyright © 2011-2022 走看看