Jump to content

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


maya75

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  :)
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.