首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取进程(gameserver)的控制台输出,并在出现单词"join“时执行一些操作

读取进程(gameserver)的控制台输出,并在出现单词"join“时执行一些操作
EN

Stack Overflow用户
提问于 2019-08-09 15:33:23
回答 2查看 275关注 0票数 0

我正在尝试设置一个linux l4d2游戏服务器,当有人加入大厅时,它会向我的团队发言发送一条消息。不知何故,我不知道如何在bash中运行该进程,以读取其内容并在有人加入时捕获。游戏服务器的输出清楚地显示了一行"XXXX加入了游戏“

Bash read output?不知何故不起作用。它冻结了这个过程。

代码语言:javascript
复制
output=$(./srcds_run)
while read -r line; do
    process "$line"
        if [ $line = "XXXX joined" ]; then
                echo "it works";
        fi
done <<< "$output"

当我运行它来启动服务器时,它在某一时刻挂起,并且没有启动。

Edit1:

Srcds_run的输出:

代码语言:javascript
复制
$ ./startServer.sh
Setting breakpad minidump AppID = 222860
Using breakpad crash handler
Forcing breakpad minidump interfaces to load
dlopen failed trying to load:
/home/steam/.steam/sdk32/steamclient.so
with error:
/home/steam/.steam/sdk32/steamclient.so: cannot open shared object file: No such file or directory
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
[S_API FAIL] SteamAPI_Init() failed; SteamAPI_IsSteamRunning() failed.
[S_API FAIL] SteamAPI_Init() failed; unable to locate a running instance of Steam, or a local steamclient.so.
[S_API FAIL] SteamAPI_Init() failed; SteamAPI_IsSteamRunning() failed.
Setting breakpad minidump AppID = 550
dlopen failed trying to load:
/home/steam/.steam/sdk32/steamclient.so
with error:
/home/steam/.steam/sdk32/steamclient.so: cannot open shared object file: No such file or directory
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Setting breakpad minidump AppID = 222860

-- Here is where srcds_run freeze --

这是用户"XXXX“连接和断开大堂时srcds_run的完整输出:

代码语言:javascript
复制
Client "XXXX" connected (127.0.0.1:27005).
Server waking up from hibernation
Initiating Reserved Wanderers
ConVarRef mat_hdr_manual_tonemap_rate doesn't point to an existing ConVar
String Table dictionary for soundprecache should be rebuilt, only found 9751 of 16341 strings in dictionary
String Table dictionary for Scenes should be rebuilt, only found 6770 of 13181 strings in dictionary
NextBot tickrate changed from 0 (0.000ms) to 3 (0.100ms)
Dropped XXXX from server (Disconnect by user.)
Server is hibernating
EN

回答 2

Stack Overflow用户

发布于 2019-08-09 15:55:19

请参阅http://forums.srcds.com/viewtopic/4446

您可以将输出写入日志文件并使用aka: tail -f /logfile|if "$(grep "XXXX“)”;然后回显"it works";fi

票数 0
EN

Stack Overflow用户

发布于 2019-08-12 11:32:30

根据我从问题中的评论和更新中收集到的信息,srcds_run是一个持续运行的进程/脚本。

所以在你的游戏结束之前output=$(./srcds_run)是不会终止的。(这是我的看法;可能是错的。)

但是,如果它是正确的,您可以尝试这样做:

代码语言:javascript
复制
$ ./srcds_run | grep --line-buffered "XXXX joined" | while read _; do
    echo it works
done

顺便说一句,从你的输出来看,你的游戏启动失败了,因为它找不到steam库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57425412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档