CLI issue: Changing STDERR

php.internals

Davy Durham

21 years ago
Hey.. seeing as there is not way specified in the docs that I can find, I thought I'd email this list as there may be an undocumented way of doing it. On Linux: I'm converting some bash scripts to php.. in the bash scripts I sometimes do at the very top: " exec 2>/path/filename " Which changes where stderr goes because it closes and reopens file descriptor 2 I've played around and around with things with some php cli scripts, but cannot do it. Is there a way of changing the actual process's file descriptor 2 to something else. (or any fd for that matter) Thanks, Davy

Christian Stadler

21 years ago
Davy Durham schrieb:
> On Linux: I'm converting some bash scripts to php.. in the bash scripts > I sometimes do at the very top: > > " exec 2>/path/filename " > > Which changes where stderr goes because it closes and reopens file > descriptor 2
[snipp]
> Is there a way of changing the actual process's file descriptor 2 to > something else. (or any fd for that matter)
Just an idea out of the blue: Did you try your luck with the Sha-Bang? e. g. #!/usr/bin/php -q 2>/path/filename Regards, Christian Stadler

Davy Durham

21 years ago
Iteresting.. but no, that won't work because the redirection is a construct of a running shell.. not the exec system function that would be interpreting that line. That got me thinking tho.. to try something like #!/bin/bash -c exec /usr/bin/php 2>/path/filename which would seem to maybe work if the php interpreter got the rest of the file as input. But, apparently bash isn't liking -c after it's already been used on a sh-bang. :( Christian Stadler wrote:

Edin Kadribasic

21 years ago
On Mar 15, 2005, at 2:36, Davy Durham wrote:
> Iteresting.. but no, that won't work because the redirection is a > construct of a running shell.. not the exec system function that would > be interpreting that line. > > That got me thinking tho.. to try something like > > #!/bin/bash -c exec /usr/bin/php 2>/path/filename > > which would seem to maybe work if the php interpreter got the rest of > the file as input. But, apparently bash isn't liking -c after it's > already been used on a sh-bang. :(
Its not bash, it's your kernel limitation (i guess linux). Most unix kernels allow only bin name + 1 arg on the shebang line. FreeBSD is a notable exception here. Edin