Jump to content
  • Advertisement
Sign in to follow this  

C Posix exec success fail?

This topic is 1784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to read and write to a external process so im using a popen type of function that forks and calls execl that works great but theres no way for me to detect if it actually launched or not if I take something I know doesnt exist I should be able to tell that it couldnt be launched


my thought is to do something like



if it makes it past execl it failed I can set a variable to let the parent process know it failed

the problem with that is the parent process would only be able to know if it waits some period of time and checks that the variable isnt set

I would like to have it work without waiting because if something hangs up it will fail and theres got to be a better way

    if( pipe(this->pipefd) != 0 ){
        return false;
    processid = fork();
    if( processid == -1 ){
        processid = 0;
        return false;
    if (processid == 0){
        // Child
        dup2(this->pipefd[0], STDIN_FILENO);
        dup2(this->pipefd[1], STDOUT_FILENO);
        dup2(this->pipefd[2], STDERR_FILENO);
        //execl("your/script", "/path/to/your/script", (char*) NULL);
        execl(command->c_str(), "/path/to/your/script", (char*) NULL);
        // Nothing below this line should be executed by child process. If so,
        // it means that the execl function wasn't successfull, so lets exit:
    // The code below will be executed only by parent. You can write and read
    // from the child using pipefd descriptors, and you can send signals to
    // the process using its pid by kill() function. If the child process will
    // exit unexpectedly, the parent process will obtain SIGCHLD signal that
    // can be handled (e.g. you can respawn the child process).
    std::cout << "Process Success" << std::endl;
    return true;
Edited by jeff8j

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!