我设法制作了一个运行.bat文件并运行控制台的程序,但是我想从该控制台获取到我的程序的行,我搜索了它但是找不到任何东西。
bat会打开一个控制台窗口,我想从该控制台窗口获取这些行。
代码:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
Process startM = new Process();
startM.StartInfo.FileName = @"C:\Users\xxxxx\Desktop\$v\xxxxx\run.bat";
startM.StartInfo.WorkingDirectory = @"C:\Users\xxxx\Desktop\$v\xxxxx";
startM.StartInfo.CreateNoWindow = true;
startM.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
startM.Start();
//startM.WaitForExit();
checkBox1.FlatAppearance.BorderColor = Color.Green;
checkBox1.FlatAppearance.CheckedBackColor = Color.Green;
checkBox1.Text = "On";
}
else if (checkBox1.Checked == false)
{
try
{
Process[] proc = Process.GetProcessesByName("test");
proc[0].Kill();
}
catch (Exception c)
{
MessageBox.Show(c.Message);
}
checkBox1.FlatAppearance.BorderColor = Color.Red;
checkBox1.Text = "Off";
}
}