I have a problem with my C# project (Windows Form Application). I have two buttons. When I click on the first one, it will open the cmd. Everything works fine.
What I want to reach: Button 2 should use an opened cmd, insert command and collect the output from it. I don't want to open cmd for every command. There will be more buttons with different commands.
Is it possible?
private void button3_Click(object sender, EventArgs e)
{
string my_script = textBox3.Text;
System.Windows.Forms.MessageBox.Show(my_id.ToString());
}
public int my_id;
public void connection_Click(object sender, EventArgs e)
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = startInfo;
process.Start();
my_id = process.Id;
}