Hooking output from the console
I was wondering if there is any way to read the output of a console command, from executing it in code. OK that's probably not the clearest way I could have put that, so let's have an example:
My project PingSweepr is, as the name implies, a simple network ping sweeper that uses the C++ system()
command to automate ping sweeping with the Windows shell ping
command.
The only problem is, there is no way to sort the results (btw, this would be used in more than just that program, in case you were wondering), which would involve parsing the command-line output of the ping
program. So basically my question is: is there any way to read the output from the shell into the program? Maybe through a system message hook or something, or is it just not pos开发者_StackOverflow社区sible?
Thanks!
Have you tried looking at the popen function? This older question has some discussion:
Capturing stdout from a system() command optimally
Here is the answer: How to execute a command and get output of command within C++ using POSIX?
精彩评论