Shell GNU-Screen -X Stuff 问题

8
OPTIONS="java -Xms1024M -Xmx1024M -jar craftbukkit.jar"
PROCESS=server01

screen -dmS $PROCESS $OPTIONS nogui             # Starting the application
screen -x $PROCESS -X stuff `printf "stop\r"`   # Closing the application
screen -x $PROCESS                              # Attaching to the terminal of the application

应用程序在开始时工作得很好,但是我在使用“stuff 'printf "stop/r"'”命令尝试停止它时遇到了问题。当我刚刚启动它,等待一段时间,然后尝试使用上述命令停止它时似乎不起作用。但奇怪的是,如果我执行screen -x $PROCESS并分离(ctrl-A & ctrl-D),然后使用Stop命令,它就可以工作。因此,有没有一种方法可以绕过screen -x $PROCESS而使用stuff printf呢?

你尝试过引用命令字符串吗?例如 screen -x $PROCESS -X "stuff \printf 'stop\r'`"`。 - twalberg
不起作用。在执行第一个屏幕 -x $PROCESS 并停止它后,甚至使其无法工作。 - user1621988
1个回答

18

添加参数 -p 0 应该可以解决问题。像这样:

screen -x $PROCESS -p 0 -X stuff `printf "stop\r"`

(来自屏幕文档:-p window 如果存在,则预选命名窗口。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接