Re: Calling Expect from PHP

unidave_at_gmail.com
Date: 06/08/05


Date: 8 Jun 2005 09:38:40 -0700


Icarus Sparry wrote:
> On 2005-06-07, unidave@gmail.com <unidave@gmail.com> wrote:
> > 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.
>
> Whilst I am not a PHP expert, you might consider adding a few commands
> to the expect script to help in debugging.
>
> exp_internal -f /tmp/expectout.txt 0
>
> will probably go a long way to helping you figure out your problem. It
> may be something as simple as you not having a TERM variable set in your
> environment.

Thanks! That pointed me in the right direction. What I learned is
that the output of the telnet process seems to be buffered and has not
"sent" all the characters so expect can match the pattern.
How do I make a spawned process not buffer the output?



Relevant Pages

  • PHP SCRIPT
    ... php classified script ... guestbook ardguest free php guestbook script ... php file upload script ...
    (sci.chem.labware)
  • 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)
  • Re: How to Add a Feeback Form
    ... I saw nothing in that script that indicates where the form is e-mailed to so ... Greg Maxey/Word MVP ... PHP or not. ... have the support available yet. ...
    (microsoft.public.frontpage.programming)
  • How best to show PHP source? (was: One page, multiple submit buttons)
    ... script to add to the top of a PHP script to enable showing its ... Maybe anybody submitting their own PHP code for critique here ... Anything posted to a newsgroup is a "snapshot" of what the ... there ought to be a FAQ for this ...
    (comp.lang.php)
  • 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. ... thinking about rewriting my whole script in a C language. ... execution of the code. ...
    (php.general)