简体   繁体   中英

How do I redirect stdout from a program continuously into a spawned process using expect?

Need to open telnet, send a few commands and then send stdout from pocketsphinx.

Currently expect will wait until the program is finished and then output everything to the telnet process. I need pocketsphix to continuously feed the spawned telnet process.

This is what I have so far:

#!/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

You can use expect command interact for connecting together two spawned processes.

By default, interact expects the user to be writing stdin and reading stdout of the Expect process itself. The -u flag (for "user") makes interact look for the user as the process named by its argument (which must be a spawned id).

This allows two unrelated processes to be joined together without using an explicit loop. To aid in debugging, Expect diagnostics always go to stderr (or stdout for certain logging and debugging information). For the same reason, the interpreter command will read interactively from stdin.

For example

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM