【发布时间】:2018-09-18 21:26:36
【问题描述】:
我有一个程序可以将一些命令写入批处理文件。当我调试这个时,程序什么也不写,只是改变了行。
有多个单独的命令,所以我使用if(ex* = true) 来指定命令序列。有一次,我将标准输入更改为console.writeline 它什么也没做。
当我使用标准信息进行调试时,批处理文件不断循环,当没有输入或输入错误时会发生这种情况。但是console.writeline 只是在应该输入第一个命令的那一刻停止。
我想也许问题是我没有时间写作?但是当我编写代码pro.waitforexit() 时,程序就会冻结。所以我不确定出了什么问题。
代码
private void button2_Click(object sender, EventArgs f)
{
pro.StartInfo.FileName = Path.Combine(textBox1.Text, "reproject_v1.2.bat");
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.CreateNoWindow = true;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.RedirectStandardError = true;
pro.OutputDataReceived += (s, e) => myMethod(e);
pro.EnableRaisingEvents = true;
pro.Start();
pro.BeginOutputReadLine();
if (ex1 == false)
{
pro.StandardInput.WriteLine(textBox1.Text + @"\\");
ex1 = true;
}
if (ex1 == true)
{
pro.StandardInput.WriteLine("inputdata.txt");
ex1 = false;
ex2 = true;
}
if (ex2 == true)
{
pro.StandardInput.WriteLine(textBox2.Text);
ex2 = false;
ex3 = true;
}
if (ex3 == true)
{
pro.StandardInput.WriteLine("y");
ex3 = false;
ex4 = true;
}
pro.StandardInput.Close();
pro.Close();
MessageBox.Show("Check output files are exist");
}
【问题讨论】:
标签: c# batch-file command-line