微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用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.

原文地址:https://www.jb51.cc/csharp/91371.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐