读程序输出C ++

时间:2011-08-23 10:57:12

标签: c++

我有一台TF2服务器,如果TF2在我离开时更新,服务器将输出:

  

您的服务器已过期。请更新并重新启动。

我怎么能用C ++观察/读取输出?

这个想法是:

         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

我的想法可能吗?

this is how server window looks like, just imagine that the last line says: "Your server is out of date. Please update and restart."

1 个答案:

答案 0 :(得分:1)

那基本上是看门狗

可以使用管道

完成解决方案

将服务器输出管道传输到C ++应用程序的标准输入(用 cin 读取它)。例如,如果您的TF2服务器是tf2.exe,而您的C ++应用程序是cpp.exe:

tf2.exe | cpp.exe

每次重新启动服务器时都需要再次执行此命令(这涉及在执行此操作后退出C ++应用程序,因为它将由命令重新运行)。