Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To achieve such behavior you should use <code>/k</code> switch to run <code>cmd.exe</code> in interactive mode.</p> <p>The problem is to separate inputs from different commands. To do this you could change the standard prompt using <code>prompt</code> command:</p> <pre><code>prompt --Prompt_C2BCE8F8E2C24403A71CA4B7F7521F5B_F659E9F3F8574A72BE92206596C423D5 </code></pre> <p>So now it is pretty easy to determine the end of command output.</p> <p>Here is the complete code:</p> <pre><code>public static IEnumerable&lt;string&gt; RunCommands(params string[] commands) { var process = new Process { StartInfo = new ProcessStartInfo("cmd") { UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true, Arguments = "/k", } }; process.Start(); const string prompt = "--Prompt_C2BCE8F8E2C24403A71CA4B7F7521F5B_F659E9F3F8574A72BE92206596C423D5 "; // replacing standard prompt in order to determine end of command output process.StandardInput.WriteLine("prompt " + prompt); process.StandardInput.Flush(); process.StandardOutput.ReadLine(); process.StandardOutput.ReadLine(); var result = new List&lt;string&gt;(); try { var commandResult = new StringBuilder(); foreach (var command in commands) { process.StandardInput.WriteLine(command); process.StandardInput.WriteLine(); process.StandardInput.Flush(); process.StandardOutput.ReadLine(); while (true) { var line = process.StandardOutput.ReadLine(); if (line == prompt) // end of command output break; commandResult.AppendLine(line); } result.Add(commandResult.ToString()); commandResult.Clear(); } } finally { process.Kill(); } return result; } </code></pre> <p>It works well but it looks like one big hack.</p> <p>I'd recommend you to use process per command instead.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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