Bash脚本在使用i3blocks在后台启动程序后暂停 [英] Bash script pauses after starting program in background with i3blocks
问题描述
我试图在i3blocks中创建一个块,当我单击它时将启动Spotify(如果已关闭).
I'm trying to make a block in i3blocks that will launch Spotify (if it's closed) when I click on it.
大多数情况下都可以正常工作,但是当Spotify启动时,脚本会停止运行,直到关闭Spotify并且该块变得无用为止.
It mostly works fine but when Spotify launches the script just stops until Spotify is closed and the block becomes useless.
如果我重新加载i3,Spotify也将关闭.
Also if i reload i3 Spotify will close.
我尝试过在后台(&)中启动Spotify并使用disown标志.但是问题一直在发生,我还在i3blocks配置文件中尝试了相同的操作(在后台启动脚本).
I've tried making Spotify launch in the background (&) and using the disown flag. but the problem keeps happening, I've also tried the same thing in the i3blocks config file (launching the script in the background).
#!/bin/sh
if pgrep spotify >/dev/null
then
spotifycli --status
case $BLOCK_BUTTON in
1) spotifycli --playpause;;
2) spotifycli --prev;;
3) spotifycli --next;;
esac
else
echo
case $BLOCK_BUTTON in
1) spotify & disown; sleep 3; spotifycli --play;;
esac
fi
推荐答案
我找到了解决方案,但我忘记了将Spotify的输出重定向到/dev/null.并且由于没有给出EOF,因此该块卡住了,无法读取Spotify的输出.
I found the solution, I forgot to redirect spotify's output into /dev/null. and since it gives no EOF the block was stuck reading spotify's output.
这篇关于Bash脚本在使用i3blocks在后台启动程序后暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!