By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Setting STDOUT in program

P: n/a
Hi!

Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.

Greetings,

Markus
Dec 11 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
cipher wrote:
Hi!

Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.

Greetings,

Markus
I don't understand. If it's outside the <?php ... ?>, they should just
be printed anyway.

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

Dec 11 '07 #2

P: n/a
On Tue, 11 Dec 2007 10:41:50 +0100, cipher <ma****************@gmail.com>
wrote:
Hi!

Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.
Anything outside <?php ?blocks will go to PHP's STDOUT (possible
captured in output buffers if you like). On the command line you can
simple direct the STDOUT (and/or STDERR) to whatever you like...
--
Rik Wasmus
Dec 11 '07 #3

P: n/a
Yes, I know that. But how can I redirect the script's output to a
file, if I call the script from command line and if I don't want to
use pipes?

On 11 Dez., 12:12, Jerry Stuckle <jstuck...@attglobal.netwrote:
cipher wrote:
Hi!
Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.
Greetings,
Markus

I don't understand. If it's outside the <?php ... ?>, they should just
be printed anyway.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Dec 11 '07 #4

P: n/a
cipher wrote:
Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.
Not sure what you're asking. STDOUT can be redirected in most shells to a
file using a construction like this:

php myscript.php >somefile.html

Or piped into STDIN of some other program using:

php myscript.php | someprogram

This is supported in bash, csh, zsh -- any shell I can think of. Even
DOS's COMMAND.COM.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 3 days, 22:23.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 11 '07 #5

P: n/a
On Tue, 11 Dec 2007 13:00:53 +0100, cipher <ma****************@gmail.com>
wrote:
On 11 Dez., 12:12, Jerry Stuckle <jstuck...@attglobal.netwrote:
>cipher wrote:
Hi!
Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.
Greetings,
Markus

I don't understand. If it's outside the <?php ... ?>, they should just
be printed anyway.
Yes, I know that. But how can I redirect the script's output to a
file, if I call the script from command line and if I don't want to
use pipes?
Why do you not 'want' to use pipes? What is it you are actually trying to
do?
--
Rik Wasmus
Dec 11 '07 #6

P: n/a
cipher wrote:
On 11 Dez., 12:12, Jerry Stuckle <jstuck...@attglobal.netwrote:
>cipher wrote:
>>Hi!
Is there a way to set STDOUT in a PHP script dynamically (by command
line argument,...)? I have large blocks of non-PHP-code (outside <?
php... ?>) and I don't want to use "print" for all these lines.
Greetings,
Markus
I don't understand. If it's outside the <?php ... ?>, they should just
be printed anyway.

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


Yes, I know that. But how can I redirect the script's output to a
file, if I call the script from command line and if I don't want to
use pipes?
(Top posting fixed)

You can't. That's the purpose of pipes.

You can buffer the output and write that to a file, but that's about it.

And please don't top post. Thanks.

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

Dec 11 '07 #7

P: n/a
cipher wrote:
Yes, I know that. But how can I redirect the script's output to a file,
if I call the script from command line and if I don't want to use pipes?
Firstly, please quote correctly. Quote only the part of the post to which
you reply, and then place your reply underneath it.

Secondly, what have you got against pipes?

Lastly, ob_start() is what you want.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 3 days, 23:06.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 11 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.