0

I'm currently having an issue where I'm trying to get the output of the command "arp -a" from CMD in my C# .net program

            Process p = null;
            string output = string.Empty;
            
            try
            {
                p = Process.Start(new ProcessStartInfo("arp", "-a")
                {
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    RedirectStandardOutput = true
                });

                output = p.StandardOutput.ReadToEnd();
                Console.WriteLine(output);
                p.Close();

            }
            catch(Exception e)
            {
                throw new Exception("Error", e);
            }

I expect to get some sort of string value in the "output" variable, but all I get is a blank "". I did test if it worked in the first place by changing it to

p = Process.Start(new ProcessStartInfo("ipconfig")

and my "output" variable was filled with what you would expect if you typed in ipconfig into CMD, so i know it worked.

any ideas?

SnXiong
  • 11
  • 3
  • Does this answer your question? [How do I access ARP-protocol information through .NET?](https://stackoverflow.com/questions/1148778/how-do-i-access-arp-protocol-information-through-net) – Ishwor Khatiwada Feb 04 '23 at 02:46
  • 1
    You should probably add `p.WaitFotrExit();` See the example in the [documentation](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput) – Klaus Gütter Feb 04 '23 at 05:16
  • The following may be helpful: https://stackoverflow.com/a/71344930/10024425 and https://stackoverflow.com/questions/71838868/process-exited-never-fires/71846819#71846819 – Tu deschizi eu inchid Feb 04 '23 at 05:46
  • 1
    You'd probably find the error if you subscribed to `StandardError`. You should use the fully-qualified name: `%windir%\System32\ARP.exe`. In C#, `System.IO.Path.Combine(Environment.GetEnvironmentVariable("windir"), "System32", "ARP.exe");` – Tu deschizi eu inchid Feb 04 '23 at 05:52

0 Answers0