0

我正在尝试与手刹的 cli 交互,但在需要时终止它的进程时遇到问题。

过程是这样开始的

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

我试过用_p.Kill(),_p.Close()和终止_p.Dispose()_p.CloseMainWindow()。最后一个有效,但仅当CreateNoWindow = false.

4

1 回答 1

0

问题是您正在启动外壳并告诉它启动手刹;_p指shell进程。杀死它显然对手刹没有影响。

您应该直接启动 Handbrake:

string command = " -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("C:\\Program Files\\Handbrake\\HandBrakeCLI.exe\", command)
{
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardError = true,
    RedirectStandardOutput = true
};
于 2013-09-05T20:23:16.703 回答