Process and Cmd.exe problem

G

Guest

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:

Code:
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();

Problem is that the executable may in most cases
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
 
G

Guest

I still haven't found a solution to my problem, but I am trying another
approach now.

If i set StartInfo.UseShellExecute = true, and StartInfo.FileName = "cmd.exe".
A cmd window will open. How can I from c# send commands to this windows?

If this is possible then my problem should be solved.


Kind Regards,
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top