Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question: How does one redirect stdout to a file?

Status
Not open for further replies.

jinkazama10

Programmer
Dec 29, 2004
4
US
I am just starting to learn PHP and I can't seem to find this anywhere. Basically I am running a script from the command line and I would like to capture the output and put it in a file but I would like to do so inside the script.

So instead of typing "myscript.php > myoutput.out" I could just type "myscript.php" and the myoutput.out would be automatically generated.

I apologize for asking what seems like such a stupid question but I honestly have tried searching the net for almost two days and I haven't been able to find a straight answer anywhere. Thanks.
 
You can use fopen to get a file handle, and then use fwrite to write your result to a file. Check out the php website for the syntax
 
What if the output is a png file? I'm using JPGraph to make pie charts. The following code doesn't work:

$handle = fopen("output.png", "w");
fwrite($handle, $graph->Stroke()); //(stroke draws the graph)
fclose($handle);

But if I use ">" it works.
 
Is there some way I can use php://stdout? Would that work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top