簡體   English   中英

發送命令以在Shell文件中打開進程

[英]Send command to open process in Shell file

在bash中如何向剛剛開始的正在運行的進程發出命令?

例如;

# Start Bluez gatttool then Connect to bluetooth device 
gatttool -b $MAC -I
connect # send 'connect' to the gatttool process?

目前我的shell腳本沒有到達connect線,因為gatttool進程正在運行。

如果您只想將字符串“connect \\ n”發送到進程,則可以使用標准管道:

echo "connect" | gatttool -b $MAC -I

如果您想與gatttool進程進行更復雜的“對話”,請查看expect (1)chat (8)工具,它允許您發送一系列字符串,並等待某些響應。

如果您更喜歡略微“輕”的管道方式,可以使用heredoc,例如:

gatttool -b $MAC -I <<EOF
connect
(...)
EOF

兩個EOF標簽之間包含的所有內容都將通過管道傳輸到命令的輸入。 我相信這不允許你在EOF標簽之間與命令進行交互,所以,如前面的答案中所提到的,你可能需要考慮使用expect,如果你需要在發送一些東西之前對命令的輸出采取行動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM