简体   繁体   中英

Read program output C++

I have a TF2 server and if TF2 gets updated while I'm away, server will output:

Your server is out of date. Please update and restart.

How could I observer/read the output with C++?

The idea is:

         1. if (output == "Your server is out of date. Please update and restart.")
         2. kill the application
         3. run update.bat
         4. start observing again

Is my idea possible?

这就是服务器窗口的样子,仅假设最后一行显示:“您的服务器已过期。请更新并重新启动。”

That's basically a watchdog .

A solution can be done using piping :

Pipe your server output to standard input from your C++ application (reading it with cin will do). For example, if your TF2 server is tf2.exe and your C++ app is cpp.exe:

tf2.exe | cpp.exe

You will need to execute this command again everytime you're restarting the server (which involves exiting the C++ app after doing so since it will be re-run by the command).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM