Bash: 从后台进程接收消息

Bash: receive messages from background process

我正在通过 cansend 向 vcan0 发送数据,同时我正在收听通过 candump vcan0 发送到 vcan0 的消息。

出于某种原因,当通过脚本向 vcan0 发送数据时,我不会收到任何消息,但是当我通过终端发送数据时,脚本会以某种方式接收数据。

cansend vcan0 004#0152FEE400000000 # sending data to vcan0
while true;
do
  msg_candump=$(candump vcan0) # read vcan0
  if [[ ${#msg_candump} > 1 ]]; then #received msg
    echo $msg_candump
  fi
done

这完成了工作:

while true;
do
  cansend vcan0 '004#0152FEE400000000'
  sleep 1
  msg_candump="$(candump vcan0 -n 1)" # read vcan0
  if [[ ${#msg_candump} > 1 ]]; then #received msg
    echo $msg_candump
    msg_candump=${msg_candump// /} # leerzeichen entfernen
    msg_candump=${msg_candump:19:8} # substring holen
    msg_candump=${msg_candump,,} #lowercase
    if [[ $msg_candump != `git log -1 --format="%h"`0 ]]; then
      echo "git pull"
      #git pull
      break
    fi
  fi
  sleep 0.025
done