PHP5 spawning PERL EXPECT using "system" does not work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
angelov
Forum Newbie
Posts: 2
Joined: Sat Mar 15, 2008 7:43 am

PHP5 spawning PERL EXPECT using "system" does not work

Post by angelov »

I am having a odd problem with PERL EXPECT. The routine I created is a simple routine to telnet to an IP Address. The routine works
- as expected when run from the UNIX command line.

When I try and call the routine from PHP - via the exec(), shell_exec() or system() function - the routine doesn't work.

The issue I am seeing - when spawning the routine from PHP is that the INPUT BUFFER (where the MATCH occurs) does not seem to "full
y" update with the data received from the server I am logging into.


Example:
Running routine from PHP - this is the output produced with EXP_INTERNAL set to "1":

Code: Select all

 
 
spawn id(5): Does `Trying 10.13.81.123...\r\r\nConnected to coveaux.atm.ca (10.13.81.123).\r\r\nEscape character is \'^]\'
.\r\r\n'
match:
  pattern #1: -re `login:'? No.
 
Waiting for new data (50 seconds)...
TIMEOUT
 

Same routine from UNIX shell - this is the output produced with EXP_INTERNAL set to "1": (this is the expected output)

Code: Select all

 
 
spawn id(3): Does `Trying 10.13.81.123...\r\r\nConnected to coveaux.atm.ca (10.13.81.123).\r\r\nEscape character is \'^]\'.\r\r\n\r
\n\r\nSunOS 5.8\r\n\r\r\n\r+-----------------------------------------------------------------------+\r\n|                         
     WARNING                                 |\r\n|                               -------                                 |\r\n|  
                                                                    |\r\n| The programs and data stored on this system are licensed
 to or are    |\r\n| private property of this company and are lawfully available only to   |\r\n| authorized users for approved purposes.  Unauthorized access to any   |\r\n| program or data on this system is not permitted, and any unauthorized |\r\n| access bey
ond this point may lead to prosecution. This system may be  |\r\n| monitored at any time for operational reasons, therefore, if you
 are  |\r\n| not an authorized user,                                               |\r\n| DO NOT ATTEMPT TO LOG IN.               
                             |\r\n|                                                                       |\r\n|                  
         Avertissement                              |\r\n|                            -------------                              |\
r\n|                                                                       |\r\n| Les programmes et les donnes stocks dans
ce systme sont viss par  |\r\n| une licence ou sont proprit prive de cette compagnie et ils ne sont|\r\n| acces
sibles lgalement qu\'aux usagers autoriss a des fins autoris\es.|\r\n| Il est interdit d\'y accder sans autorisation
, et tout accs non      |\r\n| autoris au dela de ce point peut entrainer des poursuites. Le systme|\r\n| peut en tout temps faire l\'objet d\'une surveillance. Si vous n\'tes   |\r\n| pas un usager autoris,                                  
            |\r\n| N\'ESSAYEZ PAS D\'Y ACC\311DER.                                            |\r\n+-------------------------------
----------------------------------------+\r\nlogin: '
match:
  pattern #1: -re `login:'? YES!!
<\


Can anyone provide some help -- identifying any further debugging or a hint as to what could be happening.

Platform routine is running on:
Solaris 10, running PERL 5.8.7 with appropriate libraries.
Expect.pm module -> V1.20

Apache/2.2.2 (Unix) mod_ssl/2.2.2 OpenSSL/0.9.8b PHP/5.2.5
angelov
Forum Newbie
Posts: 2
Joined: Sat Mar 15, 2008 7:43 am

Re: PHP5 spawning PERL EXPECT using "system" does not work

Post by angelov »

This is a snippet of code that is used to trigger the PERL Expect routine:

Code: Select all

 
<?php 
 
include ("php://memory");
 $commandString1 = "/opt/scripts/awoc/awoc_physical_manual_mode/avv-testing.pl > /var/tmp/avvPHP.txt 2>&1";
 
 system($commandString1);
 
?>
 
 

This is the PERL EXPECT code that runs when the PHP script calls it, the contents of "/opt/scripts/awoc/awoc_physical_manual_mode/avv-testing.pl"

Code: Select all

 
#!/usr/local/bin/perl -W
 
 
package Execct;
 
use lib "/usr/local/lib/perl5/5.8.7:/usr/local/lib/perl5/site_perl/5.8.7/sun4-solaris";
use Expect;
my $STATUS;
 
##### Create expect object.
$Expect::Exp_Internal = 1;
$Expect::Log_Stdout=1;
$Expect::Debug=3;
 
my $timeout = 50;
my $exp = new Expect;
my @parameters;
my $filehandle = "/var/tmp/avv-output.txt";
 
my $command = "telnet coveaux.atm.ca";  
my $match='login:';
 
$exp->log_file($filehandle);
$exp->spawn($command, @parameters1) or "Cannot spawn command: $!\n";
 
sleep 5;
 
$exp->expect($timeout,'-re',$match);
sleep 10;
$exp->send("\015");
 
$exp->expect(60,'-re',$match);
 
 
if ($exp->exp_error()) {
        print "\n failed connecting to coveaux \n"; }
else{
        print "\n successful connection to coveaux  \n"; }
 
print "DONE";
 
$self->{_Status} = "Fail";      
 
Execct->Execute();
exit;
 
Any help -- or direction someone can offer would be greatly appreciated. By the way - PHP is set with PHP Safe Mode = off.
Post Reply