enter code hereI want to send a command to cmd after the first command I sent will end. When I'm trying to call another command by BeginErrorReadLine()
there is an error: "An async operation already started on the stream".
How can I connect the process again and send another command? (I want to send the second command by pressing another button).
First command with cmd process:
ProcessStartInfo cmdStartInfo = new ProcessStartInfo();
cmdStartInfo.FileName = "python.exe";
cmdStartInfo.Arguments = ConfigurationManager.AppSettings["ttk"] + commandline;
cmdStartInfo.CreateNoWindow = true;
cmdStartInfo.RedirectStandardInput = true;
cmdStartInfo.RedirectStandardOutput = true;
cmdStartInfo.RedirectStandardError = true;
cmdStartInfo.UseShellExecute = false;
cmdStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_cmd = new Process();
_cmd.StartInfo = cmdStartInfo;
if (_cmd.Start())
{
_cmd.OutputDataReceived += new DataReceivedEventHandler(_cmd_OutputDataReceived);
_cmd.ErrorDataReceived += new DataReceivedEventHandler(_cmd_ErrorDataReceived);
_cmd.Exited += new EventHandler(_cmd_Exited);
_cmd.BeginOutputReadLine();
_cmd.BeginErrorReadLine();
}
else
{
_cmd = null;
}