| | |
How to call an external exceutable program.
![]() |
•
•
Join Date: Mar 2008
Posts: 97
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
/* ************************************* */ /* 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:
C++ Syntax (Toggle Plain Text)
// Find Running SSH Daemons In Linux std::string grepvals = run_command("ps aux | grep \"sshd\"");
![]() |
Other Threads in the C++ Forum
- Previous Thread: Pretty Advanced Winsock communication: HTTP servers
- Next Thread: C++ problem, using sockets
| Thread Tools | Search this Thread |
api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption equation error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tivoli tree url variable vector video win32 windows winsock wordfrequency wxwidgets






