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
+
"
"
;
}
}
}
查看全文
相关阅读:
【SQL】在含有GROUP BY的SELECT语句中如何显示COUNT()为0的结果
【SQL】SQL分页查询总结
开篇
Android Native Crash 排查思路
jmeter+ant+jenkins接口自动化测试框架
为何推荐使用线程池而不是显式创建线程原因之一—至少让线程有范围和限制
quartz 中的线程池
select in 查询结果无顺序及解决办法
Druid 数据库连接池如何根据url加载Driver
java 线程池参数
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
Java程序员的C#学习笔记(3) 类和方法(Part 1)
Java程序员的C#学习笔记(2) C#语言预览
如何在页面添加视频
CF Record
Tricks
年终做题记录
记录一些 link
网站优化的十大绝技
尚未初始化全文爬网管理器。爬网管理器完全初始化之前启动的所有爬网操作都需要重新启动。
sql 列转行
热门文章
Sql Server 跨服务器连接
ASP.NET通过Remoting service上传文件
js DIV滚动条自动滚到底部
关于获取各种浏览器可见窗口大小的一点点研究
数据结构~~二叉树和BSTs(三)(转)
linux虚拟机使用VMware的NAT共享windows主机IP上网 [转]
js里的面向对象分析(创建实例化对象)
java课程设计扫雷小游戏
【书评】规范的重要性《Clean Code》读后感
【算法】经纬度常用计算
Copyright © 2011-2022 走看看