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
"