PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Missing STDOUT, STDERR with CLI
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Missing STDOUT, STDERR with CLI

Réponse
 
LinkBack Outils de la discussion
Vieux 13/11/2007, 01h46   #1
ljb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Missing STDOUT, STDERR with CLI

Using the PHP CLI executable, if the script to run is fed to PHP via
standard input, then it seems PHP does not define any of the standard
stream constants STDIN, STDOUT, and STDERR. While I can understand not
defining STDIN, since that's where the script is, I think not defining
STDOUT and STDERR is a bug. Any comments before I open a bug report?
Confirmation?

--- Test script 'nostd.php' ---
<?php
fwrite(STDOUT, "Hello, standard output\n");
fwrite(STDERR, "Hello, standard error\n");
-------------------------------
Run: $ php nostd.php
Works as expected.
Run: $ php < nostd.php
Produces NOTICE and Warning messages about STDOUT and STDERR not defined.
  Réponse avec citation
Vieux 13/11/2007, 03h53   #2
NC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing STDOUT, STDERR with CLI

On Nov 12, 4:46 pm, ljb <lba...@pobox.com.delete.th.is> wrote:
>
> Using the PHP CLI executable, if the script to run is fed
> to PHP via standard input, then it seems PHP does not define
> any of the standard stream constants STDIN, STDOUT, and STDERR.
> While I can understand not defining STDIN, since that's where
> the script is, I think not defining STDOUT and STDERR is a bug.
> Any comments before I open a bug report?


Are you sure you're using CLI interpreter, not CGI one? What does
php_sapi_name() return?

Cheers,
NC

  Réponse avec citation
Vieux 13/11/2007, 03h58   #3
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing STDOUT, STDERR with CLI

ljb wrote:
> Using the PHP CLI executable, if the script to run is fed to PHP via
> standard input, then it seems PHP does not define any of the standard
> stream constants STDIN, STDOUT, and STDERR. While I can understand not
> defining STDIN, since that's where the script is, I think not defining
> STDOUT and STDERR is a bug. Any comments before I open a bug report?
> Confirmation?
>
> --- Test script 'nostd.php' ---
> <?php
> fwrite(STDOUT, "Hello, standard output\n");
> fwrite(STDERR, "Hello, standard error\n");
> -------------------------------
> Run: $ php nostd.php
> Works as expected.
> Run: $ php < nostd.php
> Produces NOTICE and Warning messages about STDOUT and STDERR not defined.
>


I've never tried it, but I can see why it could work that way.

When you do "php nostd.php", stdin is fed into the script, and stdout
and stderr would be, also. But, as you noticed, when you try to use
"php < nostd.php", stdin is redirected. So PHP probably doesn't open
stdout or stderr to the script, either.

You can try to submit it as a bug, but I'll give you good odds it will
be classified as "working as designed".

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 14/11/2007, 00h15   #4
ljb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing STDOUT, STDERR with CLI

nc@iname.com wrote:
> On Nov 12, 4:46 pm, ljb <lba...@pobox.com.delete.th.is> wrote:
>>
>> Using the PHP CLI executable, if the script to run is fed
>> to PHP via standard input, then it seems PHP does not define
>> any of the standard stream constants STDIN, STDOUT, and STDERR.
>> While I can understand not defining STDIN, since that's where
>> the script is, I think not defining STDOUT and STDERR is a bug.
>> Any comments before I open a bug report?

>
> Are you sure you're using CLI interpreter, not CGI one? What does
> php_sapi_name() return?


Yes, thanks, I'm using CLI. I only have Apache SAPI and CLI built, no CGI,
and php_sapi_name() returns 'cli'.
  Réponse avec citation
Vieux 14/11/2007, 00h19   #5
ljb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing STDOUT, STDERR with CLI

jstucklex@attglobal.net wrote:
> ljb wrote:
>> Using the PHP CLI executable, if the script to run is fed to PHP via
>> standard input, then it seems PHP does not define any of the standard
>> stream constants STDIN, STDOUT, and STDERR. While I can understand not
>> defining STDIN, since that's where the script is, I think not defining
>> STDOUT and STDERR is a bug. Any comments before I open a bug report?
>> Confirmation?
>>
>> --- Test script 'nostd.php' ---
>> <?php
>> fwrite(STDOUT, "Hello, standard output\n");
>> fwrite(STDERR, "Hello, standard error\n");
>> -------------------------------
>> Run: $ php nostd.php
>> Works as expected.
>> Run: $ php < nostd.php
>> Produces NOTICE and Warning messages about STDOUT and STDERR not defined.
>>

>
> I've never tried it, but I can see why it could work that way.
>
> When you do "php nostd.php", stdin is fed into the script, and stdout
> and stderr would be, also. But, as you noticed, when you try to use
> "php < nostd.php", stdin is redirected. So PHP probably doesn't open
> stdout or stderr to the script, either.
>
> You can try to submit it as a bug, but I'll give you good odds it will
> be classified as "working as designed".


Maybe I'll take that bet. I looked at the PHP source (php_cli.c function
cli_register_file_handles()), and it seems to me that it is written such
that if any of the 3 streams cannot be opened, then none are opened. I
can't see why this is necessary, but you could be right - it might be "as
designed".

I would have opened the bug already, but they just release 5.2.5 and once
they put out a new release they don't take bug reports for the 'ancient'
releases like 5.2.4.
  Réponse avec citation
Vieux 14/11/2007, 03h17   #6
ljb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing STDOUT, STDERR with CLI

lbayuk@pobox.com.nospam wrote:
> jstucklex@attglobal.net wrote:
>>...
>> You can try to submit it as a bug, but I'll give you good odds it will
>> be classified as "working as designed".

>
> Maybe I'll take that bet.... but you could be right - it might be "as
> designed".


We're both wrong, but you are closer!
Bug type was changed from CGI/CLI problem to Documentation problem
with this comment:
>>> I once tried to fix that but it just lead to crazy problems, therefore
>>> making this a documentation issue.

I like that answer. I'm going to use it myself as soon as I can.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h48.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14698 seconds with 14 queries