I am running an exe by the process like
public static void executeProcessInCMD(string methodArguments)
{
try
{
methodArguments = "\"" + methodArguments + "\"";
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.EnableRaisingEvents = true;
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.Arguments = "/c " + methodArguments;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
startInfo.Verb = "runas";
p.StartInfo = startInfo;
p.Start();
p.WaitForExit();
string error = p.StandardError.ReadToEnd();
if (error != string.Empty)
{
Console.WriteLine("error in executing cmd process : " + error);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
When you start this exe it asks for input, when you provide it an input it does some process and again asks for another input from the user, then the user has to provide another input, and so on.
I can not figure out how to do this. Like I can read the standard output from the exe one time and give the inputs as arguments to it. But how do I do it multiple times as I do from cmd?
You need to redirect the Processes Standard Output, Error and Input and attach to some events so you can interact with it programatically:
You can find further information on the StandardInput here and on the StandardOutput here.