Link to home
Start Free TrialLog in
Avatar of tomrector
tomrectorFlag for United States of America

asked on

Using Perl exec

newbe.....  know enough to be dangerous
Want to run a perl script from a php script

$cmd = "../../../cgi-bin/RentUpdate1.pl
$aryVars = array();
$intRet = 1;
$lastLine = exec($cmd, $aryVars, $intRet) ;


$aryVars = array(); // this is my problem, I need to provide this on the end of the cmd
   ?ID=$ID_1&action=save&password=''&avail=No&Name=$LName&Due=$DueItemA
as in:
"../../../cgi-bin/RentUpdate1.pl?ID=$ID_1&action=save&password=''& avail=No&Name= $LName &Due=$DueItemA"
as in:
"../../../cgi-bin/RentUpdate1.pl?ID=$ID_1&action=save&password=''& avail=No&Name= $LName &Due=$DueItemA"


or a better way if known?  "can't use require"
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
arnold,

How does that invalidate my suggestion?

The problem the OP is having is in formatting the command correctly so that it can be executed via the exec() function.  The type of output that is generated/captured and its processing wasn't part of the question, as far a I can tell.

Here's a working/tested example php script that calls the perl script.  I adjusted the perl script to only output the params data.
#!usr/bin/perl

use strict;
use warnings;
use CGI;
use Data::Dumper;

my $cgi = CGI->new;
my %params = $cgi->Vars;

print $cgi->pre(Dumper \%params);

Open in new window

<?php
    $ID_1 = 123;
    $LName = 'lastname';
    $DueItemA = 'today';
    $cmd = "perl ../cgi-bin/RentUpdate1.pl ID=$ID_1 action=save password='' avail=No Name=$LName Due=$DueItemA";
    $script_output = array();

    exec($cmd, $script_output, $intRet);
    print_r($script_output);
?>

Open in new window


PHP Output:
Array
(
    [0] => <pre>$VAR1 = {
    [1] =>           'ID' => '123',
    [2] =>           'password' => '',
    [3] =>           'action' => 'save',
    [4] =>           'Due' => 'today',
    [5] =>           'Name' => 'lastname',
    [6] =>           'avail' => 'No'
    [7] =>         };
    [8] => </pre>
)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tomrector

ASKER

Sorry I have not responeded been busy...

Still no luck,,

To be clear:
this works from the address bar
http://www.MYSITE.com/cgi-bin/RentUpdate1.pl?ID=2130&action=save&password=''&avail=No&Name=Rector&Due=08 Sep 2013
 
I need that to work calling it from a php script.
 i.e.
http://www.MYSITE.com/cgi-bin/RentUpdate1.pl?ID=$ID_1&action=save&password=''&avail=No&Name=$LName&Due=$DueItemA

I do not really need any additional resulting output.



Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial