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
+
"
"
;
}
}
}
查看全文
相关阅读:
import和include的区别
$sformat用法
如何快速理解DUT
vim_basic
UVM——寄存器模型相关的一些函数
AMBA——总线仲裁
Cache的写回策略(转)
Cache直接映射、组相连映射以及全相连映射(转载)
一起学IC验证:推荐资料合集,收藏专用(转载)
VCS仿真流程
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
那些牛掰的 HTML5的API
初识 HTML5
HTML 链接
基本的 HTML 标签
强制换行
动画 jquery-transit
图片预先加载 preloadjs
h5 点击ios键盘完成 出现键盘大小的白块
ol li 兼容
程序员常用的六大技术博客类
热门文章
java返回参数中几种常见的方法
mouseenter事件和mouseover事件
css常用填坑
constraint内部可以使用foreach
constraint_mode的使用
ref和input,output以及inout的区别
数组的搜索,队列的搜索
new()和new[]的区别
local的用法,以及和private的区别
copy和clone的区别
Copyright © 2011-2022 走看看