Hi,
Im trying to run a command line application from C# but i having some
strange problems with it.
Heres the code im using:
System.Diagnostics.Process process = new System.Diagnostics.Process();
procPath = @"c:\ae.bat";
//string procArgs = " " + fileName + " " + tempFile;
System.Diagnostics.ProcessStartInfo info = new
System.Diagnostics.ProcessStartInfo(procPath );
//info.Arguments = procArgs;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
info.RedirectStandardInput = true;
info.RedirectStandardError = true;
info.CreateNoWindow = false;
info.WorkingDirectory = @"c:\";
process.StartInfo = info;
process.Start();
StreamWriter sw = process.StandardInput;
StreamReader sr = process.StandardOutput;
StreamReader err = process.StandardError;
sw.AutoFlush = true;
System.Threading.Thread.Sleep(1000);
sw.WriteLine("Value1");
sw.WriteLine("Value2");
sw.Close();
//string ret = sr.ReadToEnd();
//string error = err.ReadToEnd();
if(process != null)
{
if(process.HasExited == false)
process.WaitForExit(3000);
if(process.HasExited == false)
process.Kill();
}
If i run this code to start any command line application they all seem
to work fine apart from the one i need. I need to run the application
with 2 parameters and then pass it more values when it asks for them.
I can see in debug view the test being returned from other
applications but the one im testing with does not return anything to
the debug window. If i run the bat file manually it works perfectly
and prompts me to enter a value but in C# i dont see any messages
coming from the application. I have tried using StreamReader on its
standardoutput but it just hangs.
Anyone have any idea why this would be happening?