solaris perl using php to output to html with variables

I am using perl to execute a php script to convert to html.  I have no problem in converting php to html when there are no variables used in the php statement, but when I attempt to add a variable to the php file, I get an error.
Below is the perl code snippet:
$myurl="build_report.php?customer=ACME";
system(`cd /var/opt/webstack/apache2/2.2/htdocs/customers/; \
 /opt/webstack/php/5.2/bin/php $myurl >/tmp/mytest.html`);

on executing the code, I get the following error:
Could no open input file: build_report.php?customer=ACME

I have tried using quotes around 'ACME', but same results.  When I do the same script with a php file that does not require the variable "customer", everything works as planned.

Any ideas on how to pass a php variable to the php script from within perl?
bray007Asked:
Who is Participating?
 
sjklein42Connect With a Mentor Commented:
The most basic way to get to the command line is through "argc" and "argv".

See http://en.wikipedia.org/wiki/Command-line_argument_parsing#PHP

PHP uses argc as a count of arguments and argv as an array containing the values of the arguments.

There are any number of ways to do it, but the most "standard" is to create an array ($args) from command-line arguments in the -foo:bar format, like this:


$args = parseArgs( $argv );
echo getArg( $args, 'customer' );
 
function parseArgs( $args ) {
        foreach( $args as $arg ) {
                $tmp = explode( ':', $arg, 2 );
                if( $arg[0] == "-" ) {
                        $args[ substr( $tmp[0], 1 ) ] = $tmp[1];
                }
        }
        return $args;
}
 
function getArg( $args, $arg ) {
        if( isset( $args[$arg] ) ) {
                return $args[$arg];
        }
        return false;
}

Open in new window


Then, when you call it, remember to use the "-" before the word customer

 $myurl="build_report.php -customer:ACME"; 

Open in new window


Let me know if you need more.
0
 
bray007Author Commented:
ultimately, I'll probably want to add multiple php variables to the statement.
0
 
sjklein42Commented:
The issue is not that you are calling the php script from perl, it is that the php script was designed to be invoked as a script on a web site, and uses CGI to get its arguments.

If you are lucky, it was also programmed to take command line arguments.  If so, the command line might look something like this:

$myurl="build_report.php customer=ACME";

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
bray007Author Commented:
I have the php script setup for a $_GET, I've also tried $_POST

when I make the changes suggested, I get:
PHP Notice: Undefined index: statuscode in /var/blah blah on line 33
PHP Notice: Undefined index: customer in /var blah blah on line 34.

any thoughts on what I would need to change?
0
 
sjklein42Commented:
It may help to know that you can pick up command line arguments using the $_SERVER array.

0
 
bray007Author Commented:
I'll try that avenue.  If you have a sample script for PHP where I can get it to return the argument in the php, I would appreciate it and reward the points.

Thanks for your help.
0
 
FishMongerCommented:
Why are you using a backticks statement inside the system call?  If you want to capture the output of the command, then use backticks or the qx operator.  If you don't need to capture the command's output in Perl, then use the system function or open a pipe.

Another option you might want to look at is to use the PHP::Interpreter module instead of the system call.  The module makes it easy to pass the needed POST/GET data.

http://search.cpan.org/~aff/PHP-Interpreter-1.0.2/lib/PHP/Interpreter.pm
0
 
bray007Author Commented:
i am still have some issues on this, but I believe the original responder pointed me in the right direction to resolve the issue.  Full points will be awarded.  
Thank you!!
0
 
bray007Author Commented:
great help in pointing me to the proper direction to finish the task.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.