sheredom / subprocess.h

🐜 single header process launching solution for C and C++
The Unlicense
1.14k stars 100 forks source link

Binary is not found if the full path is not provided when using subprocess_create without environment options #28

Closed JoseTomasTocino closed 3 years ago

JoseTomasTocino commented 3 years ago

In RHEL 7.3, when using subprocess_create with a 0 for the environment option, if I don't specify the full path of the binary, the call to execvp fails and returns 255.

    const char * command_line[] = { "sleep", "10", NULL };

    struct subprocess_s subprocess;

    int result = subprocess_create(command_line, 0, &subprocess);

    if (0 != result)
    {
        std::cerr << "Error with subprocess" << std::endl;
    }

    int retcode = 0;

    result = subprocess_join(&subprocess, &retcode);

    if (0 != result)
    {
        std::cerr << "Error joining subprocess" << std::endl;
    }

    std::cout << "Ret code: " << retcode << std::endl; // This prints 255

However, if I use any environment option, like subprocess_option_inherit_environment, your lib uses execve instead, which does need to have the full path. Here's a better explanation for that behavior.

To my understanding, the behavior should be consistent in both cases.

sheredom commented 3 years ago

Yeah it should be consistent - good catch! Fancy doing a PR? Otherwise I'll get to this when I can 😄

JoseTomasTocino commented 3 years ago

Alright! Will try my best. Expect my PR.