使用C#捕获nslookup shell输出

我有一个命令行进程,我想在C#中自动化和捕获.

在命令行中,我键入:

nslookup

这会启动一个shell,它给我一个>提示.在提示符下,我输入:

ls -a mydomain.local

这将返回主DNS服务器及其连接的物理机的本地CNAME列表.

我想做的是从C#自动化这个过程.如果这是一个简单的命令,我只会使用Process.StartInfo.RedirectStandardOutput = true,但第二步的要求正在绊倒我.

解决方法

processstartinfo si = new processstartinfo("nslookup");
si.RedirectStandardInput = true;
si.RedirectStandardOutput = true;
Process nslookup = new Process(si);
nslookup.Start();
nslookup.StandardInput.WriteLine("ls -a mydomain.local");
nslookup.StandardInput.Flush();
// use nslookup.StandardOutput stream to read the result.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...