Calling Expect from PHP

unidave_at_gmail.com
Date: 06/07/05


Date: 7 Jun 2005 10:54:50 -0700

I'm calling an expect script from an exec() call in PHP. When I run it
from the command line it works o.k. From within php, the expect script
behaves differently.

I set the timeout to 10 seconds
I have a total of 4 expect statements in the expect script.
It takes a total of 40 seconds to execute the expect script indicating
to me that each expect statement is timing out.
I cannot get the typical output from the -d command option back into
the PHP script for output on the web page.

PHP version 4.3.9
Apache version 2.0.52
Expect version 5.42.1
Running under Redhat Enterprise WS 4

Here's my PHP:
------------------------------------------------------
$email = "example@domain.com";
$password = "fubar";
$command = "/var/www/html/AP/pop3auth.sh " . $email . " " . $password;
exec($command, $output, $ret);
print "<pre>";
print_r($output) . "\r";
print "</pre>";
print $ret;
------------------------------------------------------

Here's "pop3auth.sh"
------------------------------------------------------
#!/usr/bin/expect

set timeout 10
set login [lindex $argv 0]
set password [lindex $argv 1]
spawn telnet mail.domain.com 110
expect "+OK"
send "USER $login\r"
expect "+OK"
send "PASS $password\r"
expect {
        "ERR" {
                set exitcode 1
        }
        "+OK" {
                set exitcode 0
        }
}
send "QUIT\r"
expect eof

exit $exitcode
----------------------------------------------------------

None of the patterns match. I've tried "*OK*" and many other variants.
 The only pattern that matches is "*".

I hope I've given enough information. I really hope someone has seen
this before.

Thanks in advance
Dave