我正在尝试设置一个linux l4d2游戏服务器,当有人加入大厅时,它会向我的团队发言发送一条消息。不知何故,我不知道如何在bash中运行该进程,以读取其内容并在有人加入时捕获。游戏服务器的输出清楚地显示了一行"XXXX加入了游戏“
Bash read output?不知何故不起作用。它冻结了这个过程。
output=$(./srcds_run)
while read -r line; do
process "$line"
if [ $line = "XXXX joined" ]; then
echo "it works";
fi
done <<< "$output"当我运行它来启动服务器时,它在某一时刻挂起,并且没有启动。
Edit1:
Srcds_run的输出:
$ ./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的完整输出:
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发布于 2019-08-09 15:55:19
请参阅http://forums.srcds.com/viewtopic/4446
您可以将输出写入日志文件并使用aka: tail -f /logfile|if "$(grep "XXXX“)”;然后回显"it works";fi
发布于 2019-08-12 11:32:30
根据我从问题中的评论和更新中收集到的信息,srcds_run是一个持续运行的进程/脚本。
所以在你的游戏结束之前output=$(./srcds_run)是不会终止的。(这是我的看法;可能是错的。)
但是,如果它是正确的,您可以尝试这样做:
$ ./srcds_run | grep --line-buffered "XXXX joined" | while read _; do
echo it works
done顺便说一句,从你的输出来看,你的游戏启动失败了,因为它找不到steam库。
https://stackoverflow.com/questions/57425412
复制相似问题