| | |
How to call an external exceutable program.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 99
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 beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






