c# - 使用 C# 捕获 nslookup shell 输出

标签 c# shell .net-2.0 nslookup

我有一个命令行进程,我想在 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. 

关于c# - 使用 C# 捕获 nslookup shell 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/353601/

相关文章:

c# - Azure WebJob 丢失连接字符串

c# - 如何高效计算连续数的位数乘积?

python - 优化 shell 脚本 (bash) 以提高性能

linux - 与 grep 命令一起使用的 Shell 脚本变量

bash - 你如何使用命令启动 Unix screen 命令?

vb.net - 是否可以同时迭代两个 IEnumerable 对象?

来自 SQL 数据库表的 C# 类

c# - 将引用属性映射到抽象父级

c# - 使用 SQL Server 管理对象将存储过程从一个 SQL Server 2008 复制到另一个 SQL Server 2008

winforms - 按钮图像离按钮顶部太远;离按钮底部太近