Question

I have a PHP script at C:\WampServer\www\dnsmasq\php\dnsmasq.php:

function uploadConfig() {
    exec('C:\cygwin64\bin\expect -f /home/Dave/bin/scp.expect asdf', $output, $exitCode);
    print_r($output);
    print($exitCode);
}

Which calls a script at /home/Dave/bin/scp.expect:

#!/usr/bin/expect -f

set password [lindex $argv 0]

spawn /usr/bin/scp /home/Dave/bin/test root@192.168.1.1:/etc/test

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$password\r"
    }
}

interact

The file to upload contains one line:

Testing

Running the uploadConfig function results in the following output on the page:

Array ( [0] => spawn /usr/bin/scp /home/Dave/bin/test root@192.168.1.1:/etc/test [1] => root@192.168.1.1's password: ) 0 

The file appears on the server at /etc/test but it is blank, i.e. it doesn't contain the word "Testing".

I can run the expect script inside a cygwin shell and it uploads the file with the content:

$ expect -f /home/Dave/bin/scp.expect asdf

I'm not sure where the failure point is when I try to do this from PHP.

Était-ce utile?

La solution

You use interact when you want to, guess what, interact with the spawned application interactively.

If you want to spawn a program, send some data to it, and wait for it to finish, use expect eof instead.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top