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语句把DBF导入SQLServer
(转载)SQLServer存储过程返回值总结
(转载)MS SQL Server 未公开的加密函数有哪些?
(转载)SQL语句,纵列转横列
(转载)直接用SQL语句把DBF导入SQLServer
(转载)用SQL语句创建Access表
(转载)根据数据字典表定义的表结构,生成创建表的SQL语句
(转载)sql语句解决分页问题
(转载)总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
(转载)异构数据库之间完全可以用SQL语句导数据
原文地址:https://www.cnblogs.com/cl1024cl/p/6204946.html
最新文章
CentOS设置固定IP上网的方法(转)
Web 性能压力测试工具(WebBench)
SQL查询 thinkphp
linux 常用的命令记录
PHP 中巧用数组降低程序的时间复杂度
php 获取文字首字母(包含生僻字)
is marked as crashed and last (automatic?) repair failed
linux 修改mysql 最大连接数
mysql批量导入sql文件
Apache与Nginx的比较
热门文章
重新开启更新博客
ruby Math
Ruby 命名
Ruby -reverse',upcase' & '.downcase'
Ruby
Ruby -puts and print
Ruby 变量
Ruby 的环境搭建及安装
Ruby
随想
Copyright © 2011-2022 走看看