Thursday, 5 September 2013

C# - unable to terminate Process with CreateNoWindow set to true

C# - unable to terminate Process with CreateNoWindow set to true

I'm trying to interact with handbrakes's cli and I'm having problems
terminating it's process when needed.
Process is started like so
string command = "/c \"C:\\Program
Files\\Handbrake\\HandBrakeCLI.exe\" -i " + disk.Info.Name + " -o
" + disk.Info.VolumeLabel + ".mkv -t " + titleNum + " -e x264 -q
18.0 -f mkv -4 --decomb --loose-anamorphic --modulus 2 -m
--x264-preset medium --h264-profile high --h264-level 4.1";
_p = new Process();
_p.StartInfo = new ProcessStartInfo("cmd.exe", command)
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
_p.OutputDataReceived += OutputCallback;
_p.ErrorDataReceived += OutputCallback;
_p.Start();
_p.BeginErrorReadLine();
_p.BeginOutputReadLine();
_p.WaitForExit();
I have tried terminating it with _p.Kill(), _p.Close(), _p.Dispose() and
_p.CloseMainWindow(). The last one works but only when CreateNoWindow =
false.

No comments:

Post a Comment