?
Solved

solaris perl using php to output to html with variables

Posted on 2011-09-06
9
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
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 2000 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Six Sigma Control Plans
Suggested Courses

752 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