Swift 的 NSTask 在 C++ 中的模拟是什么?

问题描述 投票:0回答:0

我使用以下 Swift 代码启动我的启动守护进程:

    let task = Process()
    
    task.launchPath = "/bin/launchctl"
    task.arguments = ["load", plistPath]
    
    let pipe = Pipe()
    task.standardOutput = pipe
    task.standardError = pipe
    
    task.launch()
    
    task.waitUntilExit()
    
    let nExitCode = task.terminationStatus
    
    //Get output from running launchctl
    let data = pipe.fileHandleForReading.readDataToEndOfFile()
    let strLaunchCtlOutput = String(decoding: data, as: UTF8.self)
    
    if(nExitCode == 0)
    {
        //Success running the process, but we need to parse the output

    }
    else
    {
        //Error
    }

现在我需要在另一个用 C++ 编写的进程中做同样的事情。我必须做

fork()
等吗

有什么建议吗?

swift macos nstask launch-daemon
© www.soinside.com 2019 - 2024. All rights reserved.