[哇哇哇!!!!]如何与一个控制台程序交互?

TAL_King 2004-11-10 02:24:16
举个简单的需求例子吧:
得到 ipconfig /all 的输出结果。
...全文
87 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
TAL_King 2004-11-10
  • 打赏
  • 举报
回复
:)

搞定,多谢 brightheroes(闭关|那一剑的风情) 以及1,2楼的朋友。
brightheroes 2004-11-10
  • 打赏
  • 举报
回复
结果

Windows IP Configuration



Host Name . . . . . . . . . . . . : jasonjin

Primary Dns Suffix . . . . . . . :

Node Type . . . . . . . . . . . . : Unknown

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

DNS Suffix Search List. . . . . . : 14.emedchina.net



Ethernet adapter 本地连接:



Connection-specific DNS Suffix . : 14.emedchina.net

Description . . . . . . . . . . . : Realtek RTL8139/810x Family Fast Ethernet NIC

Physical Address. . . . . . . . . : 00-0E-A6-51-F5-0F

Dhcp Enabled. . . . . . . . . . . : Yes

Autoconfiguration Enabled . . . . : Yes

IP Address. . . . . . . . . . . . : 192.168.100.204

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.100.1

DHCP Server . . . . . . . . . . . : 192.168.100.1

DNS Servers . . . . . . . . . . . : 210.51.183.181

210.51.25.115

202.106.0.20

Lease Obtained. . . . . . . . . . : 2004年11月10日 9:04:54

Lease Expires . . . . . . . . . . : 2004年11月10日 21:04:54
brightheroes 2004-11-10
  • 打赏
  • 举报
回复
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.Arguments = "/all";
p.StartInfo.FileName = "ipconfig.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();

StreamReader sr = p.StandardOutput;
while(sr.Peek() > -1)
{
Console.WriteLine(sr.ReadLine());
}
北京的雾霾天 2004-11-10
  • 打赏
  • 举报
回复
比如
C:\ipconfig >a.txt

就生成一个a.txt文件.
wwwcampus 2004-11-10
  • 打赏
  • 举报
回复
ipconfig /all >> c:\a.txt

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧