为什么 grep 在此命令中不起作用?

为什么 grep 在此命令中不起作用?

我在 Wine 中运行 GTA San Andreas,尽管当我退出游戏时它会挂在终端中,并且该进程仍然有剩余资源,这导致它无法退出。所以我做了这个命令,我认为它会循环游戏输出中的行,并在发现剩余资源时杀死它:

bash -c 'cd /opt/GTA/San-Andreas && wine ./gta_sa.exe | while read line; do if [[ $(echo $line | grep -i "leftover resource") ]]; then killall gta_sa.exe; exit; fi; done'

我在 gta_sa.exe 挂起之前得到了以下输出:

fixme:d3d:wined3d_device_uninit_3d Something's still holding the implicit swapchain.
fixme:d3d:wined3d_device_decref Device released with resources still bound, acceptable but unexpected.
fixme:d3d:wined3d_device_decref Leftover resource 0x539a5e8 with type WINED3D_RTYPE_TEXTURE_2D (0x2).
fixme:d3d:wined3d_device_decref Leftover resource 0x1b8ea8 with type WINED3D_RTYPE_TEXTURE_2D (0x2).
fixme:d3d:wined3d_device_decref Leftover resource 0x1b8cb0 with type WINED3D_RTYPE_TEXTURE_2D (0x2).
fixme:d3d:wined3d_device_decref Leftover resource 0x1b74b8 with type WINED3D_RTYPE_TEXTURE_2D (0x2).

然而,它不起作用,进程仍然挂起。为什么这个命令不起作用?

请注意:这不是关于 Wine 的问题,而是关于我制作的脚本的问题。

答案1

从 的输出的字符wine我得出结论,它是某种错误消息,因此可能被重定向到 stderr,而不是 stdout。在这种情况下,管道不会传输消息,并且下一个命令 ( while) 的输入中没有任何内容。为了解决这个问题,您需要通过在管道前面wine添加来将 stderr 重定向到 stdout 。2>&1|

相关内容