Running a batch file remotely, displaying results to user & allowing user to provide input
<p>I've made a page that allows users to view a list of batch files on a server, and run them. </p>

<p>The problem is when a batch file requires input such as "Press any key to continue" or "Press Y if you're sure you want to continue". Currently my code is providing input to preset situations:</p>

<pre><code>if (outputLine.Contains("Y or N"))
    inputLine = "Y";
if (outputLine.Contains("pause"))
    inputLine = "X";
</code></pre>

<p>But I now want to give the user the ability to provide input instead of my code. </p>

<p>I've spent most of today researching how to do this and have come up with nothing.</p>

<p>Here's my code:</p>

<pre><code>private void RunScript(int scriptId)
{
    ScriptData data = new ScriptData();
    Script script = data.GetScript(scriptId);

    ProcessStartInfo psi = new ProcessStartInfo()
    {
        FileName = script.Path,
        RedirectStandardOutput = true,
        RedirectStandardInput = true,
        UseShellExecute = false,
        CreateNoWindow = false
    };

    Process proc = new Process();
    proc.StartInfo = psi;

    proc.Start();

    StreamReader reader = proc.StandardOutput;
    StreamWriter writer = proc.StandardInput;

    string outputLine;
    string inputLine = string.Empty;
    string display = string.Empty;

    while (!reader.EndOfStream)
    {
        outputLine = reader.ReadLine();
        display += outputLine + "\r\n";

        if (inputLine != string.Empty)
            display += inputLine + "\r\n";

        inputLine = string.Empty;
        if (outputLine.Contains("Y or N"))
            inputLine = "Y";
        if (outputLine.Contains("pause"))
            inputLine = "X";

        if (inputLine != string.Empty)
            writer.WriteLine(inputLine);
    }

    display = Server.HtmlEncode(display);
    display = display.Replace("\r\n", "&lt;br /&gt;");
    litOutput.Text = display;
}
</code></pre>
