调用“期望” C++ 中的脚本过程
我使用expect/spawn实现了一个shell,并将命令从远程服务器发送到SCP文件,该服务器在需要时自动发送密码。
该脚本在 UNIX 终端上运行良好。
尽管如此,我还是尝试通过 C++ 过程使用此脚本。它已被 system() 甚至 popen() 函数调用但没有成功。 返回此错误:“ioctl(raw): I/O error” 有人可以有任何线索吗?
这是我的脚本:
#!/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
"
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.
The script works fine on UNIX terminal.
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?
This is my script:
#!/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
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试的第一件事是放弃 bash 脚本(无论如何似乎都存在引用问题)
但真正的问题是 stdio 通道/pty 如何被期望进程继承(我不确定这里的正确术语)
The first thing I'd try is to ditch the bash script (there appear to be quoting issues anyway)
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)