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
+
"
"
;
}
}
}
查看全文
相关阅读:
day24 Pyhton学习 反射
正则表达式练习
day23 Pyhton学习 昨日回顾.re模块.序列化模块
day22 函数整理
day22 Pyhton学习 re模块和正则表达式
day21 Pyhton学习 模块
函数整理
一个关于浮点数运算需要注意的地方
关于逻辑运算案例笔记
数据的表现形式和进制之间的转换
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
Android_Handler
Android_gridVIew
Android_listView
Android_ViewPager
ViewFlipper的简单使用实现图片轮播效果
Android_AutoCompleteTextView,MultiAutoCompleteTextView
Android_Dialog
13.mysql基本查询
11.常见数据库操作2
9.简单理解ajax
热门文章
10.常见数据库操作1
8.网络编程知识
7.对进程、线程、异步的理解
6.传递、继承、私有化及深浅拷贝。
5.简单理解递归思想
4.入门字符串练习
3.字典常用功能
day26 Pyhton select功能语句实现
day25 Pyhton学习 MD5加密.日志
day25 Pyhton学习 约束和异常处理
Copyright © 2011-2022 走看看