Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #1757 > unrolled thread
| Started by | Bob Smith <bsmith@sudleydeplacespam.com> |
|---|---|
| First post | 2011-05-21 21:06 -0400 |
| Last post | 2011-05-22 12:17 -0400 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.php
Detecting Redirected Output Bob Smith <bsmith@sudleydeplacespam.com> - 2011-05-21 21:06 -0400
Re: Detecting Redirected Output Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-21 23:14 -0400
Re: Detecting Redirected Output "Twayne" <nobody@devnull.spamcop.net> - 2011-05-22 09:04 -0400
Re: Detecting Redirected Output Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-22 13:06 +0200
Re: Detecting Redirected Output Bob Smith <bsmith@sudleydeplacespam.com> - 2011-05-22 12:17 -0400
| From | Bob Smith <bsmith@sudleydeplacespam.com> |
|---|---|
| Date | 2011-05-21 21:06 -0400 |
| Subject | Detecting Redirected Output |
| Message-ID | <c7idnTS_Udwd_EXQnZ2dnUVZ_jKdnZ2d@giganews.com> |
Running under Win7, a script I'm writing needs to vary its behavior depending upon whether or not the output from PHP is being redirected. That is, I want to know from within the PHP script whether it's called as php foo.php or php foo.php > outfile None of the Output Control Functions appears to be helpful. Way back in DOS days, there was an IOCTL call which the program could use to distinguish those two cases. Is there anything comparable in PHP? -- _________________________________________ Bob Smith -- bsmith@sudleydeplacespam.com To reply to me directly, delete "despam".
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-05-21 23:14 -0400 |
| Message-ID | <ir9v2l$rnv$2@dont-email.me> |
| In reply to | #1757 |
On 5/21/2011 9:06 PM, Bob Smith wrote: > Running under Win7, a script I'm writing needs to vary its behavior > depending upon whether or not the output from PHP is being redirected. > That is, I want to know from within the PHP script whether it's called as > > php foo.php > > or > > php foo.php > outfile > > None of the Output Control Functions appears to be helpful. > > Way back in DOS days, there was an IOCTL call which the program could > use to distinguish those two cases. Is there anything comparable in PHP? > Nope. Not possible in PHP. And it shouldn't be, either. The purpose of a redirect is to be able to save the output. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "Twayne" <nobody@devnull.spamcop.net> |
|---|---|
| Date | 2011-05-22 09:04 -0400 |
| Message-ID | <irb1l1$7sq$1@dont-email.me> |
| In reply to | #1759 |
In news:ir9v2l$rnv$2@dont-email.me, Jerry Stuckle <jstucklex@attglobal.net> typed: > On 5/21/2011 9:06 PM, Bob Smith wrote: >> Running under Win7, a script I'm writing needs to vary >> its behavior depending upon whether or not the output >> from PHP is being redirected. That is, I want to know >> from within the PHP script whether it's called as php foo.php >> >> or >> >> php foo.php > outfile >> >> None of the Output Control Functions appears to be >> helpful. Way back in DOS days, there was an IOCTL call which the >> program could use to distinguish those two cases. Is >> there anything comparable in PHP? > > Nope. Not possible in PHP. And it shouldn't be, either. > The purpose of a redirect is to be able to save the > output. So says the exalted high troll of the newsgroups whose only intent in life is to issue meaningless and uncalled for criticisms in order to make up for his own lack of power by stealing it from others.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-05-22 13:06 +0200 |
| Message-ID | <2708352.dWV9SEqChM@PointedEars.de> |
| In reply to | #1757 |
Bob Smith wrote: > Running under Win7, a script I'm writing needs to vary its behavior > depending upon whether or not the output from PHP is being redirected. > That is, I want to know from within the PHP script whether it's called as > > php foo.php > > or > > php foo.php > outfile > > None of the Output Control Functions appears to be helpful. > > Way back in DOS days, there was an IOCTL call which the program could > use to distinguish those two cases. Is there anything comparable in PHP? In PHP, yes; but not on Windows, as the POSIX extension is not available there (according to the manual): <http://lmgtfy.com/?q=php+cli+redirection+-http> PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [next] | [standalone]
| From | Bob Smith <bsmith@sudleydeplacespam.com> |
|---|---|
| Date | 2011-05-22 12:17 -0400 |
| Message-ID | <T9udnX3XdaK4qkTQnZ2dnUVZ_rqdnZ2d@giganews.com> |
| In reply to | #1762 |
On 5/22/2011 7:06 AM, Thomas 'PointedEars' Lahn wrote:
> Bob Smith wrote:
>
>> Running under Win7, a script I'm writing needs to vary its behavior
>> depending upon whether or not the output from PHP is being redirected.
>> That is, I want to know from within the PHP script whether it's called as
>>
>> php foo.php
>>
>> or
>>
>> php foo.php> outfile
>>
>> None of the Output Control Functions appears to be helpful.
>>
>> Way back in DOS days, there was an IOCTL call which the program could
>> use to distinguish those two cases. Is there anything comparable in PHP?
>
> In PHP, yes; but not on Windows, as the POSIX extension is not available
> there (according to the manual):
>
> <http://lmgtfy.com/?q=php+cli+redirection+-http>
Having just learned that this is trivial in Python, I looked more
carefully at PHP on Windows and found a couple of ways to tell if STDOUT
has been redirected:
1. $fd = fopen ('php://stdout', "w");
if (ftell ($fd) === false)
echo "STDOUT not redirected.\n";
else
echo "STDOUT redirected.\n";
fclose ($fd);
2. $fd = fopen ('php://stdout', "w");
$a = fstat ($fd);
if ($a['dev'] != 0) // or ['rdev']
echo "STDOUT not redirected.\n";
else
echo "STDOUT redirected.\n";
fclose ($fd);
There also is a difference in $a['mode'] which I did not pursue.
--
_________________________________________
Bob Smith -- bsmith@sudleydeplacespam.com
To reply to me directly, delete "despam".
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web