捕获用C#NSLOOKUP外壳输出 [英] Capturing nslookup shell output with C#
问题描述
我有一个命令行程序,我想在C#自动化和捕获。
在命令行中,I型:
NSLOOKUP
这将启动一个shell,给了我一个>提示符。在提示符下,我然后键入:
LS -a mydomain.local
此从我的主DNS服务器和它们所连接的物理机返回本地的CNAME的列表。
我想这样做的是自动从C#这个过程。如果这是一个简单的命令,我只想用Process.StartInfo.RedirectStandardOutput =真实的,但第二个步骤的要求绊倒了我。
的ProcessStartInfo SI =新的ProcessStartInfo(Nslookup的);
si.RedirectStandardInput =真;
si.RedirectStandardOutput =真;
流程NSLOOKUP =新工艺(SI);
nslookup.Start();
nslookup.StandardInput.WriteLine(LS -a mydomain.local);
nslookup.StandardInput.Flush();
//使用nslookup.StandardOutput流读取结果。
I have a command-line process I would like to automate and capture in C#.
At the command line, I type:
nslookup
This launches a shell which gives me a > prompt. At the prompt, I then type:
ls -a mydomain.local
This returns a list of local CNAMEs from my primary DNS server and the physical machines they are attached to.
What I would like to do is automate this process from C#. If this were a simple command, I would just use Process.StartInfo.RedirectStandardOutput = true, but the requirement of a second step is tripping me up.
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.
这篇关于捕获用C#NSLOOKUP外壳输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!