windowswinapicreateprocess

Why isn't this code executing a hello world executable


Why isn't this code running my hello world c executable

#include <windows.h>
#include <string>

int main()
{
    // path for hello world compiled program 
    std::string app_path = "C:\\Users\\test\\Desktop\\a.exe";

    BOOL inherit_handles = true;
    PROCESS_INFORMATION pi;
    STARTUPINFO si;

    CreateProcessA(app_path.c_str(),
                   NULL,
                   NULL,
                   NULL,
                   inherit_handles,
                   CREATE_NEW_CONSOLE|CREATE_PROTECTED_PROCESS|DETACHED_PROCESS,
                   0,
                   NULL,
                   &si,
                   &pi);
    return 0;
}

I am clueless to why not output is given, even when I use > out.txt, although I do see some cpu usage spikes in process hacker

I also tried to use calc.exe instead of a.exe but this also didn't help


Solution