How to keep writing the results of system("ping 10.50.132.10 -t");
in a text file using C++?
Asked
Active
Viewed 1,684 times
0

Romain Francois
- 17,432
- 3
- 51
- 77

Aan
- 12,247
- 36
- 89
- 150
-
Possible duplicate of http://stackoverflow.com/questions/5919622/how-to-store-the-system-command-output-in-a-variable – RonaldBarzell Dec 03 '12 at 13:53
2 Answers
5
A way is to do directly with shell command:
system("ping 10.50.132.10 -t >> file.txt");
After your operations, you can read from "file.txt"!

Luca Davanzo
- 21,000
- 15
- 120
- 146
3
There are a couple solutions to this. The first and simplest would be to simple add a redirect in the system
call:
system("ping 10.50.132.10 -t > some_file.txt");
Another and more advanced way would be to read the output into your program, and write it out to file yourself. For this look either at _popen
or CreateProcess
.

Some programmer dude
- 400,186
- 35
- 402
- 621