I managed to make a program to run a .bat file and run a console, but I want to get the lines from that console to my program, I searched for it but I couldn't find anything.
The bat will open a console window and I want to get the lines from that console window.
Code :
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";
}
}