呼叫“期望" C ++流程中的脚本 [英] Call "expect" script in C++ process
问题描述
我实现了一个使用Expect/spawn的shell,并从远程服务器向SCP文件发送命令,该服务器会在需要时自动发送密码.
I realized a shell using expect/spawn and send commands to SCP files from a remote server which send automatically the password when it is needed.
该脚本在UNIX终端上可以正常工作.
The script works fine on UNIX terminal.
尽管如此,我还是尝试通过C ++进程使用此脚本.它已经被system()甚至popen()函数调用而没有成功. 返回此错误:"ioctl(raw):I/O错误" 有人可能有任何线索吗?
Nevertheless, I tried to use this script throough a C++ process. It has been called by system() or even popen() function without sucess. This error is returned: "ioctl(raw): I/O error" Someone could have any clue?
这是我的脚本:
#!/bin/bash
targetHost=$1
password=$2
sourceFile=$3
destRep=$4
expect -c "
spawn /usr/bin/scp -q $targetHost:$sourceFile $destRep
expect -i $spawn_id {
"*password:*" { send -i $spawn_id $password\r\n; interact }
eof { exit }
}
exit
"
推荐答案
我要尝试的第一件事是抛弃bash脚本(无论如何似乎都在引用问题)
The first thing I'd try is to ditch the bash script (there appear to be quoting issues anyway)
#! /usr/bin/env expect -f
foreach {targetHost password sourceFile destRep} $argv break
spawn /usr/bin/scp -q $targetHost:$sourceFile $destRep
expect -i $spawn_id {
"*password:*" { send -i $spawn_id $password\r; interact }
eof { exit }
}
但是真正的问题是stdio频道/pty是如何通过期望过程继承的(我不确定此处是否使用正确的术语)
But the real problem is how the stdio channels/pty get inherited by the expect process (I'm not sure of the proper terminology here)
这篇关于呼叫“期望" C ++流程中的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!