visual c++ - Run a process as a synchronous operation from a Win32 application -


I have an existing utility application, let's call it use.exe, it's a command line tool that inputs from the command line And creates a file on disk, let's say an image file

I want to use it by using use.exe in another application. Although it should be synchronous so that the file is present when processing is turned on.

For example (psudeo)

  bool CreateImageFile (params) {// ret is used. Exe program exit code int rate = runprocess ("util.exe", params); Returns == 0; }  

Is there a single Win32 API call that will run the process and wait until it is finished? I looked at CreateProcess, but as soon as it tries to start it comes back, I saw the shellexecute but it also looks a bit ugly was synchronous

There is no single API, but this is actually a more interesting general question for Win32 apps. You can use CreateProcess or ShellExecuteEx and WaitForSingleObject to handle the process. GetExitCodeProcess will give you exit code of the program at that point. See for a simple sample code.

Although it completely blocks your main thread, and you can give serious deadlock problems under Win32 messaging scenarios. Let's suppose that the EXE transmission produced is transmitted so that it can not proceed until all the windows have processed the message - but you can not move because you are waiting for it. Deadlock Since you are using full command line programs, this problem is probably not applicable to you though do you care that the command line program is hanging for a while?

The best general solution for normal applications might be to launch a process and wait on threads and post the message back in your main window when the thread runs at full. When you receive the message, you know that it is safe to continue, and there are no deadlock problems.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -