Hello,
I am doing an automatic backup service using c# and VS2003.
To achieve this i must call an executable file. So far I have made
it all work using Process, code looks like this:
Expand|Select|Wrap|Line Numbers
- Process cmd = new Process();
- StreamWriter sw;
- StreamReader sr;
- StreamReader err;
- cmd.StartInfo.RedirectStandardInput = true;
- cmd.StartInfo.RedirectStandardOutput = true;
- cmd.StartInfo.RedirectStandardError = true;
- cmd.StartInfo.CreateNoWindow = true;
- cmd.StartInfo.UseShellExecute = false;
- cmd.StartInfo.FileName = "cmd.exe";
- cmd.Start();
- sw = cmd.StandardInput;
- sr = cmd.StandardOutput;
- err = cmd.StandardError;
- sw.AutoFlush = true;
- if (textBox1.Text != "") // textBox1 contains the path+name of .exe
- sw.WriteLine(textBox1.Text);
- sw.Close();
- richTextBox1.Text = sr.ReadToEnd();
- richTextBox1.Text += err.ReadToEnd();
ask for a password. I have found no way how to check
for this and supply the password. After executing the
above code the Process terminates.
How can I tell the Process to wait if the executable is
waiting for input? Or is there another way to accomplish
this??
Kind Regards,
Robert