title: c# execute command line like command prompt?
body: <p>I want to write a c# code to execute some command prompt lines and store the result into a global variable in c# to be used for further processing in other part of the code in c#.</p>
  
  <p>I bought a device and I installed its driver. The only way for me to obtain its data is using command line in command prompt. There is no API available. But, I want to do in c# so that is why I am having trouble.</p>
  
  <p>I have some code and it doesn't works for some reason. Note, I used argument input = "date" is only for illustration purpose. My work is not using "date" but some arguments to obtain data.</p>
  
  <pre><code>static void Main(string[] args)
  {
      System.Diagnostics.Process process = new System.Diagnostics.Process();
      System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
      startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
      // the cmd program
      startInfo.FileName = "cmd.exe";
      // set my arguments. date is just a dummy example. the real work isn't use date.
      startInfo.Arguments = "date";
      startInfo.RedirectStandardOutput = true;
      startInfo.UseShellExecute = false;
      process.StartInfo = startInfo;
      process.Start();
      // capture what is generated in command prompt
      var output = process.StandardOutput.ReadToEnd();
      // write output to console
      Console.WriteLine(output);
      process.WaitForExit();
  
      Console.Read();
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>