Dear All, I want to open another exe file in my C++ program. Let the exe file be A.exe. So I used shell execute inside my C++ program to open the file but as A.exe writes in a file certain data that I will use in the next step of my program I must wait till A.exe finishes. The execution time of A.exe can't be predicted, it may take a flash or it may take days!!, but I must wait till it finishes its code and output the file that I want to read. So is there a fucntion that I can call to wait till A.exe that I openned with shell execute finishes?. Please explain clearly as I'm not a proffesional C++ programmer. Note: A.exe don't set a file openning restrictions, so I can open the file even it contains only part of the data not all of it. Thanks in advance.

Assuming Windows, here's an example of waiting for an exe to finish.

STARTUPINFO si = {sizeof (STARTUPINFO)};
    PROCESS_INFORMATION pi;
    CreateProcess( "\\windows\\notepad.exe", NULL,
        0, 0, 0, 0, 0, 0, &si, &pi );
    WaitForSingleObject( pi.hProcess, INFINITE );

Thanks a lot for your reply nucleon.
yes, I'm using windows. Can you please explain the code you have written to me?. And can you please state the name of the header file to include?.

Please anyone tell me the answer to my question. I can't execute the code that nucleon have written. Please tell me if there is a specific function that can be used with ShellExecute not with Create process that will make my Code wait till the A.exe file finishes.
Thanks in advance.

It seems fairly self-explanatory. Remember to (of course) look the functions up on MSDN. Just include windows.h to use the code above.

If you must use ShellExecute (and there certainly can be reasons for that) then use ShellExecuteEx since it gives you the process handle.

Thanks a lot for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.