Answers for "how to execute cmd command in c# and get output"

C#
0

how to execute command line in c# and get response

using (Process p = new Process())
{
	// set start info
    p.StartInfo = new ProcessStartInfo("cmd.exe")
    {
    	RedirectStandardInput = true,
        UseShellExecute = false,
        WorkingDirectory = @"C:\"
    };
    // event handlers for output & error
    p.OutputDataReceived += p_OutputDataReceived;
    p.ErrorDataReceived += p_ErrorDataReceived;

    // start process
    p.Start();
    // send command to its input
    p.StandardInput.Write("dir" + p.StandardInput.NewLine);
    //wait
    p.WaitForExit();
}
Posted by: Guest on September-04-2020
0

how to execute cmd command in c# and get output

Just does not work.
Posted by: Guest on June-24-2021

Code answers related to "how to execute cmd command in c# and get output"

C# Answers by Framework

Browse Popular Code Answers by Language