Pipe output with expect spawn

Viewed 5588

I have script for copying some files by ssh to other server. I'm using tar for compressing files to on farchive and decompress it from stdout on other machine.

set timeout -1

# user info
set port [lindex $argv 0]
set login [lindex $argv 1]
set password [lindex $argv 3]
set host [lindex $argv 2]

#tar info
set sdir [lindex $argv 4]
set ddir [lindex $argv 5]

spawn tar cf - $sdir | ssh -p $port $login@$host tar xf - -C $ddir

expect "*?(yes/no)" {
    send "yes\r"
}

expect "*?assword" {
    send "$password\r"
}

expect "#" {
    send "ls $ddir -la\r"
}

expect "#" {
    send "exit\r"
}

interact

But '|' doesn't work with spawn. I tried to find any solution, but there no any suitable way for me. Can you give me an advice for this question?

2 Answers
Related