每行运行cmd行

时间:2016-03-11 11:07:22

标签: c# cmd

我正在编写一个应用程序。我想从文本变量中逐步运行进程,然后在文本框中显示它。 这是我的代码:

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");
}

它不起作用.Txtresult是空的

0 个答案:

没有答案
相关问题