Solved

solaris perl using php to output to html with variables

Posted on 2011-09-06
9
256 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:bray007
  • 5
  • 3
9 Comments
 

Author Comment

by:bray007
ID: 36493491
ultimately, I'll probably want to add multiple php variables to the statement.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 36493521
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
 

Author Comment

by:bray007
ID: 36493537
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 16

Expert Comment

by:sjklein42
ID: 36493566
It may help to know that you can pick up command line arguments using the $_SERVER array.

0
 

Author Comment

by:bray007
ID: 36493601
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
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 36493649
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
 
LVL 28

Expert Comment

by:FishMonger
ID: 36495990
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
 

Author Comment

by:bray007
ID: 36585194
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
 

Author Closing Comment

by:bray007
ID: 36585199
great help in pointing me to the proper direction to finish the task.  Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question