1

I'm writing an application.I want to run process step by step from text variable and then show it on a textbox. Here my code:

void RunCmd(string cmd){
    StringCollection values = new StringCollection();
        p = new System.Diagnostics.Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.StartInfo.FileName = @"cmd";
        p.StartInfo.Arguments= cmd;
        p.StartInfo.CreateNoWindow = true;
        p.Start();

        p.OutputDataReceived += (s, e) => {
            lock (values) {
                values.Add(e.Data);
            }
        };

        p.BeginOutputReadLine();
        foreach (string sline in values)
            txtresult.AppendText(Environment.NewLine + sline);
}

void btnAction_Click(object sender, EventArgs e)
{
    RunCmd("/c test.exe ABC && test.exe A5");
    RunCmd("test.exe 22");
}

It not working.Txtresult is empty

Jandy
  • 349
  • 1
  • 6
  • 18

0 Answers0