title: How to send commands to cmd in C#
body: <p>I am coding a program in C# and I need to open cmd.exe, send my commands and get its answers.
  I searched around and found some answers to take diagnostics.process in use.</p>
  
  <p>Now, I have two problems:</p>
  
  <ol>
  <li>When I get the output of process, the output is not shown on the cmd consoule itself.</li>
  <li>I need to call g95 compiler on the system. When I call it from cmd manually, it is invoked and does well, but when I call it programmatically, I have the this error: "g95 is not recognized as an internal or external ..."</li>
  </ol>
  
  <p>On the other hand, I only found how to send my commands to cmd.exe via arguments and <code>process.standardInput.writeline()</code>. Is there any more convenient method to use. I need to send commands when the cmd.exe is open.</p>
  
  <p>I am sending a part of my code which may help:</p>
  
  <pre><code>System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
  myProcess.StartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe");
  
  //myProcess.StartInfo.Arguments = "/c g95";
  myProcess.StartInfo.UseShellExecute = true;
  myProcess.StartInfo.RedirectStandardInput = true;
  myProcess.StartInfo.RedirectStandardOutput = true;
  myProcess.StartInfo.RedirectStandardError = true;
  myProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(myProcess_OutputDataReceived);
  myProcess.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(myProcess_ErrorDataReceived);
  
  myProcess.Start();
  myProcess.BeginOutputReadLine();
  myProcess.BeginErrorReadLine();
  myProcess.StandardInput.WriteLine("g95 c:\\1_2.f -o c:\\1_2.exe");
  </code></pre>