title: How I can execute a Batch Command in C# directly?
body: <p>I want to execute a batch command and save the output in a string, but I can only execute the file and am not able to save the content in a string.</p>
  
  <p>Batch file: </p>
  
  <blockquote>
    <p>@echo off</p>
    
    <p>"C:\lmxendutil.exe" -licstatxml -host serv005 -port
    6200>C:\Temp\HW_Lic_XML.xml notepad C:\Temp\HW_Lic_XML.xml</p>
  </blockquote>
  
  <p>C# code: </p>
  
  <pre><code>private void btnShowLicstate_Click(object sender, EventArgs e)
  {
       string command = "'C:\\lmxendutil.exe' -licstatxml -host lwserv005 -port 6200";
  
       txtOutput.Text = ExecuteCommand(command);
  }
  
  static string ExecuteCommand(string command)
  {
       int exitCode;
       ProcessStartInfo processInfo;
       Process process;
  
       processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
       processInfo.CreateNoWindow = true;
       processInfo.UseShellExecute = false;
       // *** Redirect the output ***
       processInfo.RedirectStandardError = true;
       processInfo.RedirectStandardOutput = true;
  
       process = Process.Start(processInfo);
       process.WaitForExit();
  
       // *** Read the streams ***
       string output = process.StandardOutput.ReadToEnd();
       string error = process.StandardError.ReadToEnd();
  
       exitCode = process.ExitCode;
  
       process.Close();
  
       return output; 
  }
  </code></pre>
  
  <p>I want the output in a string and do this directly in C# without a batch file, is this possible?</p>