cpp: how to call another cpp .exe file in a cpp program

I am working on Windows system and I have already had an executable cpp program, in its file, there is an a.exe file.
Now I am coding another cpp program, and I want to execute the a.exe in this program.
Something like this:

void ExecuteA_exe()
{
     // some function to execute a.exe
}

I have tried the three functions: WinExec, ShellExecute and CreateProcess.
But I get the same result: Nothing —- no error but no running a.exe.
My a.exe is just a simple cpp program, when I run it, I can get the console window. But If I run the second program, meaning that I try to call the function ExecuteA_exe() to run the a.exe, but I get nothing. I can’t see the console window of a.exe.

Here is my little test:

int main()
{
    ShellExecute(GetDesktopWindow(), "open", "C:UsersThomasDocumentsbloomberg - apiMarketDataAgentDebugMarketDataAgent.exe", "", "", SW_SHOWNORMAL);

    cout << endl;
    system("pause");
    return 0;
}

When I run this program, it will end without any error but also, no running a.exe. Anyway, I am waiting for the console of a.exe but I can’t get it.


Source: windows

Leave a Reply