title: How to send series of commands to a command window process?
body: <p>We have a few commands(batch files/executables) on our network path which we have to call to initialize our 'development environment' for that command window. It sets some environmental variables, adds stuff to the Path etc. (Then only whatever working commands we type will be recognized &amp; I don't know what goes inside those initializing commands)</p>
  
  <p>Now my problem is, I want to call a series of those 'working commands' using a C# program, and certainly, they will work only if the initial setup is done. How can I do that? Currently, I'm creating a batch file by scratch from the program like this for example: </p>
  
  <pre><code>file.Writeline("InitializationStep1.bat")
  file.Writeline("InitializeStep2.exe")
  file.Writeline("InitializeStep3.exe")
  </code></pre>
  
  <p>Then the actual commands</p>
  
  <pre><code>file.Writeline("Dowork -arguments -flags -blah -blah")
  file.Writeline("DoMoreWork -arguments -flags -blah -blah")
  </code></pre>
  
  <p>Then finally close the file writer, and run this batch file. </p>
  
  <p>Now if I directly execute this using <code>Process.&lt;strike&gt;Run&lt;/strike&gt;Start("cmd.exe","Dowork -arguments");</code> it won't run.</p>
  
  <p>How can I achieve this in a cleaner way, so that I have to run the initialization commands only once? (I could run <code>cmd.exe</code> each time with all three initializers, but they take a lot of time so I want to do it only once)</p>