-1

我一直在尝试为我的统一 VR 游戏编写一个快速脚本,以便在运行时从 Azure Kinect 相机开始录制,并在应用程序关闭时关闭此脚本/录制。要运行他们的演示录制应用程序,您可以k4arecorder.exe output.mkv在命令提示符下运行,然后按下Ctrl-C关闭摄像头,这样程序就可以正确保存文件(请参阅Azure Kinect SDK)。

我已经能够使用以下代码成功打开脚本并开始从相机录制,但我无法Ctrl-C在弹出命令提示符下输入(或根本没有任何文本)以阻止相机运行。而且我不能使用Process.StandardInput.Close(),因为我正在运行它useShellExecute=True

.exe 会在Ctrl-C输入后保存摄像机记录,因此我确实需要在完全停止程序之前以某种方式关闭标准输入。

    ProcessStartInfo startInfo;
    Process process;

    void Start()
    {
        startInfo = new ProcessStartInfo();
        startInfo.FileName = @"C:\Program Files\Azure Kinect SDK v1.4.1\tools\k4arecorder.exe";
        startInfo.Arguments = System.IO.Directory.GetCurrentDirectory() + "\\output_testing.mkv";

        process = new Process {StartInfo = startInfo};
        process.Start();
    }

我还尝试了另一种方法,重定向 StandardInput,但是在弹出命令提示符下我根本看不到任何文本,并且我尝试关闭 stdin 并将任何内容打印到命令提示符也没有奏效。例如,我从来没有在命令提示符下看到任何东西在运行:

ProcessStartInfo startInfo;
    Process process;
    void Start()
    {
        startInfo = new ProcessStartInfo();
        startInfo.FileName = @"C:\Program Files\Azure Kinect SDK v1.4.1\tools\k4arecorder.exe";
        startInfo.Arguments = System.IO.Directory.GetCurrentDirectory() + "\\output_testing.mkv";
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true;
        startInfo.RedirectStandardError = true;
        startInfo.RedirectStandardInput = true;
        startInfo.CreateNoWindow = false;

        process = new Process {StartInfo = startInfo};
        process.Start();

        process.StandardInput.WriteLine("testing");
        string output = process.StandardOutput.ReadToEnd();
        UnityEngine.Debug.Log(output);
    }

    void OnApplicationQuit()
    {
        // this will just perpetually wait until I close the window cause cntrl-c not going thru
        process.StandardInput.Close();
        process.WaitForExit();
        process.Close();
    }

非常感谢任何提示!我觉得这两种方法都必须有办法解决,但我做不到。这是 Unity 2019.4.1f1 和 Azure Kinect SDK v1.4.1(虽然我不认为这是一个错误)。

4

1 回答 1

0

嗨,对我有用的一件事是使用:

void OnApplicationQuit() { process.CloseMainWindow(); }

于 2021-02-26T21:25:03.347 回答