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



Relevant Pages

  • PHP SCRIPT
    ... php classified script ... guestbook ardguest free php guestbook script ... php file upload script ...
    (sci.chem.labware)
  • Re: i cant call subversion from php with shell_exec()
    ... But when I put it in a PHP script ... "svn update" command never run. ... So apparently PHP does have permission to run the svn update command. ...
    (comp.lang.php)
  • HELP! Really anoying apache/php problem
    ... outcome in text files (programmed in harbour, ... run it again from the command line it works great (so i think it's no rights ... and run it like 'php test.php' it works great!, but if i include it in an ... set_time_limitin my script, ...
    (alt.php)
  • Re: [PHP] SSH and php
    ... % % Is it possible to run a SSH command from php? ... it's possible to run any command from php. ... There are ways to do that -- I personally would create a kick script ...
    (php.general)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)