tamaro
November 23rd, 2006, 08:15 AM
I use the following code to run an application which creates an output txt file. for some reason the cmd.exe process does not die - it stays in the task manager process list until I close my C# application.
How come??
Process p = new System.Diagnostics.Process();
System.IO.StreamWriter sw;
System.IO.StreamReader sr;
ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
string strCubistCmd = "START /B CubistX -f input.txt > output.txt";
sw.AutoFlush = true;
sw.WriteLine("C:");
sw.WriteLine("CD \"C:\\Program Files\\Cubist\"");
sw.WriteLine("START /B CubistX -f input > output");
// wait till output file is created or timeout
int i = 0;
while (!File.Exists("output.txt") & i<10)
{
Thread.Sleep(1000);
i++;
}
p.CloseMainWindow(); // the process does not create a window, but i thought this might help...
p.Close();
How come??
Process p = new System.Diagnostics.Process();
System.IO.StreamWriter sw;
System.IO.StreamReader sr;
ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
string strCubistCmd = "START /B CubistX -f input.txt > output.txt";
sw.AutoFlush = true;
sw.WriteLine("C:");
sw.WriteLine("CD \"C:\\Program Files\\Cubist\"");
sw.WriteLine("START /B CubistX -f input > output");
// wait till output file is created or timeout
int i = 0;
while (!File.Exists("output.txt") & i<10)
{
Thread.Sleep(1000);
i++;
}
p.CloseMainWindow(); // the process does not create a window, but i thought this might help...
p.Close();