如何查看arp -a "ProcessStartInfo.RedirectStandardOutput&quo

本文关键字:ProcessStartInfo RedirectStandardOutput quo quot arp 何查看 | 更新日期: 2023-09-27 18:10:11

我有一个小的windows应用程序调用命令提示符,然后将结果分配给richTextBox。我想将命令提示符"arp -a"的结果分配给datagridview。我该怎么做呢?

下面是代码:
    private void button1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.FileName = "cmd.exe";
        process.StartInfo.Arguments = "/C  arp -a";
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.Start();
        string output = process.StandardOutput.ReadToEnd();
        process.Close();
        richTextBox1.Text = output;
   }

如何查看arp -a "ProcessStartInfo.RedirectStandardOutput&quo

您必须"解析"输出,例如:

// add columns to your grid (could also be done in designer)
dataGridView1.Columns.AddRange(
    new DataGridViewTextBoxColumn(),
    new DataGridViewTextBoxColumn(), 
    new DataGridViewTextBoxColumn());
while (!process.StandardOutput.EndOfStream)
{
    string[] values = process.StandardOutput.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
    if (values.Length == 3) dataGridView1.Rows.Add(values);
}
相关文章:
  • 没有找到相关文章