C++'s “system” without wait (Win32)

后端 未结 3 989
忘掉有多难
忘掉有多难 2021-01-14 21:34

I have got a program which checks if there\'s a version update on the server. Now I have to do something like

if(update_avail) {
    system(\"updater.exe\");         


        
3条回答
  •  借酒劲吻你
    2021-01-14 22:14

    There is no fork() in Win32. The API call you are looking for is called ::CreateProcess(). This is the underlying function that system() is using. ::CreateProcess() is inherently asynchronous: unless you are specifically waiting on the returned process handle, the call is non-blocking.

    There is also a higher-level function ::ShellExecute(), that you could use if you are not redirecting process standard I/O or doing the waiting on the process. This has an advantage of searching the system PATH for the executable file, as well as the ability to launch batch files and even starting a program associated with a document file.

提交回复
热议问题