0

How to keep writing the results of system("ping 10.50.132.10 -t"); in a text file using C++?

Romain Francois
  • 17,184
  • 3
  • 49
  • 75
Aan
  • 11,437
  • 34
  • 84
  • 144

2 Answers2

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
  • 19,947
  • 14
  • 113
  • 144
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
  • 380,411
  • 33
  • 383
  • 585