加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用C#捕获nslookup shell输出

发布时间:2020-12-15 04:29:40 所属栏目:百科 来源:网络整理
导读:我有一个命令行进程,我想在C#中自动化和捕获. 在命令行中,我键入: nslookup 这会启动一个shell,它给我一个提示.在提示符下,我输入: ls -a mydomain.local 这将返回主DNS服务器及其连接的物理机的本地CNAME列表. 我想做的是从C#自动化这个过程.如果这是一个
我有一个命令行进程,我想在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读