# CLI issue: Changing STDERR

- Thread: https://externals.io/message/15437
- Original archive: https://news-web.php.net/php.internals/15437
- Started by Davy Durham on 2005-03-14T23:41:51+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15437 — Davy Durham — 2005-03-14T23:41:51+00:00

URL: https://externals.io/message/15437#15437

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

---

## #15443 — Christian Stadler — 2005-03-15T00:55:00+00:00

URL: https://externals.io/message/15437#15443 · In reply to: #15437

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

---

## #15445 — Davy Durham — 2005-03-15T01:36:02+00:00

URL: https://externals.io/message/15437#15445 · In reply to: #15443

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:

>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

---

## #15448 — Edin Kadribasic — 2005-03-15T01:57:12+00:00

URL: https://externals.io/message/15437#15448 · In reply to: #15445

> 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
