Hi,

I have to call an external executable program (prog2) from within my program (prog1) and then use the output of that exceutable program (prog2) in program (prog1) after calling it.

I have to manipulate the output obtained from progam (prog2) in program (prog1) and then perform this iteration n times.

I do not how to do this. Please let me know.

Thanks

Hi,

Could you give a small example.

Thanks

/* ************************************* */
/* Function To Run A Shell Command, And  */
/* Read The Output Back Into Our Program */
/* ************************************* */
std::string run_command(string cmd)
{
        string data;
        FILE *stream;
        char buffer[1024];

        // Open The Command With Read Flag  
        stream = popen(cmd.c_str(), "r");
        while (fgets(buffer, 1024, stream) != NULL) {
                data.append(buffer);
        }
        pclose(stream);

        return data;
}

Usage Case:

// Find Running SSH Daemons In Linux
std::string grepvals = run_command("ps aux | grep \"sshd\"");

Hi,

Thanks for the sample code. If possible could you also refer me a book or article online where i can read more about it.