[英]Read program output C++
I have a TF2 server and if TF2 gets updated while I'm away, server will output: 我有一台TF2服务器,如果我不在时更新TF2,服务器将输出:
Your server is out of date.
您的服务器已过期。 Please update and restart.
请更新并重新启动。
How could I observer/read the output with C++? 如何使用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). 将您的服务器输出通过管道传递到C ++应用程序的标准输入(使用cin读取即可)。 For example, if your TF2 server is tf2.exe and your C++ app is cpp.exe:
例如,如果您的TF2服务器是tf2.exe,而您的C ++应用程序是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). 每次重新启动服务器时,您将需要再次执行此命令(这涉及在执行此操作后退出C ++应用程序,因为它将由该命令重新运行)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.