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
+
"
"
;
}
}
}
查看全文
相关阅读:
Android中颜色的使用
Android中android:layout_weight的使用方法
Android中android:layout_gravity和android:gravity的使用方法
Android中的尺寸单位
一个小demo
新版markdown解析工具
LoadShader辅助函数
github 博客地址
不一样的快速排序
C++ 重构 markdown–> HTML 的引擎
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
ANDROID自定义视图——onMeasure流程,MeasureSpec详解
Tortoisegit 在Windows7下pull代码提示403错误,解决办法
HashMap原理
AsyncTask 源码分析
线程
像素密度
调节音量的流程
TCP协议与UDP协议的区别
android:configChanges="locale"
layout_weight
热门文章
java ==和equals的区别
Json解析
打开链接
安卓截图
android中baselineAligned和baselineAlignedChildIndex
android项目导入问题
Android和Html中的颜色代码
Android中添加竖线和横线的方法
Android中如何设置字体大小
android刷新或clean后R.java不见了怎么处理
Copyright © 2011-2022 走看看