Answers for "how to execute command line in c# and get response"

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

Code answers related to "how to execute command line in c# and get response"

C# Answers by Framework

Browse Popular Code Answers by Language