I am executing the Cmd commands using C# console application by creating new process. facing issue in killing the process on WaitforExit.
Basically I want to terminate the command execution on waitforexit. Please help.
Code:
string Command = "perl Simple_File_Copy.pl"
ProcessStartInfo procStartInfo = new ProcessStartInfo();
procStartInfo.FileName = "cmd.exe";
procStartInfo.Arguments = "/c " + Command + " & exit";
procStartInfo.WorkingDirectory = ProcessDirectory;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.RedirectStandardInput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = false;
procStartInfo.WindowStyle = ProcessWindowStyle.Normal;
Process process = Process.Start(procStartInfo);
if (!process.WaitForExit((int)TimeSpan.FromSeconds(10).TotalMilliseconds)) //wait for 10 seconds
{
Console.WriteLine("TimeOut Exception");
// the perl command still contiue its exeuction if I use any of
below.
//Want to terminate the command line step at this stage
process.Kill();
process.CloseMainWindow();
process.Close();
}