Jump to content

Archived

This topic is now archived and is closed to further replies.

maya75

I execute a php script from Perl => my return value = 0 instead of a string

Recommended Posts

Hello,

When I do this in a Linux command line :
[CODE]perl -e 'system("php myscript.php a b")'[/CODE]it works, i.e. I have a string as the return value.

But If I do this inside my perl script :
[CODE]$var = system("php myscript.php a b");[/CODE]it doesn't works, i.e. I have 0 as the return value ($var).

The code of script.php is :
[CODE]#!/usr/bin/php -q
<?php
echo $argv[1].$argv[2];
?>
[/CODE]

Can you see the problem ? Thanks a lot for any help  :)

Share this post


Link to post
Share on other sites
Unfortunately the system() command only returns the status result of the command argument.  Therefore if it executes properly a 0 will be returned.  That's why your var is set to 0.  The only way to get the output of a command is to use the pipe command and have the output redirected to a file handler... like so:
[code]
open (HTML_FILE, "php myscript.php a b |");[/code]

Share this post


Link to post
Share on other sites
Wow, thanks for your quick and appropriate answer  :o  :D

I'm going to have a look at the pipe command + file handler proposition you gave.

Kind Regards.

Share this post


Link to post
Share on other sites
Hi again,
I found an alternative method which works fine  ;D :

[code]$var = `php myscript.php a b`;[/code]

Bye! Thanks again.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.