Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this:</p> <pre><code>public static void LaunchApplication(string runCommand, string commandArguments, string workingDir, string informMessage, Action&lt;string&gt; redirectOutput, Action&lt;string&gt; redirectError) { try { Process applicationProcess = new Process(); applicationProcess.StartInfo.FileName = runCommand; applicationProcess.StartInfo.WorkingDirectory = workingDir; applicationProcess.StartInfo.Arguments = commandArguments; applicationProcess.StartInfo.UseShellExecute = false; applicationProcess.EnableRaisingEvents = true; applicationProcess.StartInfo.CreateNoWindow = true; if (redirectOutput != null) applicationProcess.OutputDataReceived += (s, data) =&gt; redirectOutput(data.Data); if (redirectError != null) applicationProcess.ErrorDataReceived += (sErr, errData) =&gt; redirectError(errData.Data); GeneralUtils.WriteHeadlineToConsole(informMessage); applicationProcess.Start(); if (redirectOutput != null) applicationProcess.BeginOutputReadLine(); if (redirectError != null) applicationProcess.BeginErrorReadLine(); applicationProcess.WaitForExit(); GeneralUtils.WriteHeadlineToConsole("Finished " + informMessage); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } </code></pre> <p>Usage:</p> <pre><code>LaunchApplication("cmd.exe", "/C ipconfig /all", "C:\\Windows", "Test", s =&gt; Console.WriteLine("HELLO: " + s)); </code></pre> <p><strong>PS</strong>: The following code is awful! <code>AccessDeniedException</code> might be thrown, CPU is going crazy!</p> <pre><code>while (Process.GetProcesses().Any(runningProcess =&gt; runningProcess.Id == applicationProcess.Id)) { } </code></pre> <p>Use <code>applicationProcess.WaitForExit();</code> instead!</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