2017-05-18 21 views
0

需要打開telnet,發送一些命令,然後從pocketsphinx發送stdout。如何將程序中的stdout不斷重定向到使用expect的衍生進程?

目前預計將等到程序結束,然後將所有內容輸出到telnet進程。 我需要pocketsphix來連續提供催生的telnet進程。

這是我到目前爲止有:

#!/usr/bin/expect -d 
set send_human {.1 .3 1 .05 2} 
spawn telnet 192.168.1.104 23 
expect 「*」 
send "\x01"; send "2\r" 
expect 「:」 
send -h "hello world\r" 
send -h "goodbye world\r" 
send -h "Test Test Test\r" 
send -- [exec pocketsphinx_continuous -infile speech.wav 2> /dev/null ]\n 

回答

1

可以使用期望命令interact連接在一起的兩個產生的進程。

默認情況下,interact希望用戶可以編寫標準輸入和讀取過程中期待自己 的標準輸出。 -u標誌(對於「用戶」)使得交互作爲由其參數 (其必須是衍生的id)命名的過程來尋找用戶。

這允許兩個不相關的進程連接在一起而不使用顯式循環。爲了幫助調試 ,Expect診斷程序總是轉到stderr(或者stdout用於某些日誌記錄和調試信息)。 出於同樣的原因,解釋器命令將從stdin交互式讀取。

例如

set send_human {.1 .3 1 .05 2} 
spawn telnet 192.168.1.104 23 
expect 「*」 
send "\x01"; send "2\r" 
expect 「:」 
send -h "hello world\r" 
send -h "goodbye world\r" 
send -h "Test Test Test\r" 

set sid_telnet $spawn_id 
spawn pocketsphinx_continuous -infile speech.wav 2> /dev/null 

interact -u $sid_telnet 
+0

這工作。謝謝。 – corebinary

相關問題