Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is much easier to run the process directly instead of using creating a batch file that you later execute since you lose some control since you are using a batch script layer.</p> <p>Use this code instead:</p> <pre><code> /// &lt;summary&gt; /// Execute external process. /// Block until process has terminated. /// Capture output. /// &lt;/summary&gt; /// &lt;param name="binaryFilename"&gt;&lt;/param&gt; /// &lt;param name="arguments"&gt;&lt;/param&gt; /// &lt;param name="currentDirectory"&gt;&lt;/param&gt; /// &lt;param name="priorityClass"&gt;Priority of started process.&lt;/param&gt; /// &lt;returns&gt;stdout output.&lt;/returns&gt; public static string ExecuteProcess(string binaryFilename, string arguments, string currentDirectory, ProcessPriorityClass priorityClass) { if (String.IsNullOrEmpty(binaryFilename)) { return "no command given."; } Process p = new Process(); p.StartInfo.FileName = binaryFilename; p.StartInfo.Arguments = arguments; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.UseShellExecute = false; if (!String.IsNullOrEmpty(currentDirectory)) p.StartInfo.WorkingDirectory = currentDirectory; p.StartInfo.CreateNoWindow = false; p.Start(); // Cannot set priority process is started. p.PriorityClass = priorityClass; // Must have the readToEnd BEFORE the WaitForExit(), to avoid a deadlock condition string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); if (p.ExitCode != 0) { throw new Exception(String.Format("Process '{0} {1}' ExitCode was {2}", binaryFilename, arguments, p.ExitCode)); } //string standardError = p.StandardError.ReadToEnd(); //if (!String.IsNullOrEmpty(standardError)) //{ // throw new Exception(String.Format("Process '{0} {1}' StandardError was {2}", // binaryFilename, // arguments, // standardError)); //} return output; } </code></pre> <p>I use it in a number of projects and it works like a charm.</p> <p>If you HAVE to go the batch script route, make sure that the batch script set exitcode properly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload