Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 maya75

maya75
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 August 2006 - 04:45 PM

Hello,

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

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

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

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

#2 Corona4456

Corona4456
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts
  • LocationEl Paso, TX

Posted 23 August 2006 - 04:55 PM

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:
open (HTML_FILE, "php myscript.php a b |");

What is the CoronaMatrix?

#3 maya75

maya75
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 August 2006 - 07:42 PM

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.

#4 Corona4456

Corona4456
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts
  • LocationEl Paso, TX

Posted 23 August 2006 - 07:48 PM

no problem... glad to help
What is the CoronaMatrix?

#5 maya75

maya75
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 August 2006 - 07:33 AM

Hi again,
I found an alternative method which works fine  ;D :

$var = `php myscript.php a b`;

Bye! Thanks again.

#6 Corona4456

Corona4456
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts
  • LocationEl Paso, TX

Posted 24 August 2006 - 04:40 PM

ah... nice :)... thanks for the info
What is the CoronaMatrix?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users