0

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

Romain Francois
  • 17,432
  • 3
  • 51
  • 77
Aan
  • 12,247
  • 36
  • 89
  • 150

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
  • 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