C++的"系统"无需等待(Win32)

gor*_*tde 2 c++ windows background execute

我有一个程序,检查服务器上是否有版本更新.现在我必须做类似的事情

if(update_avail) {
    system("updater.exe");
    exit(0);
}
Run Code Online (Sandbox Code Playgroud)

但无需等待"updater.exe"完成.否则我无法替换我的主程序,因为它正在运行.那么如何执行"updater.exe"并立即退出?我知道*nix方式fork等等,如何在Windows中执行此操作?

Pro*_*ica 5

使用CreateProcess(),它以异步方式运行.然后,您只需要确保updater.exe可以写入原始EXE,您可以通过等待或重试直到原始进程结束.(当然有宽限期.)