Jump to content

[SOLVED] output to file echo backspace problem


abazoskib

Recommended Posts

PHP 5.2.6 (cli) (built: May  8 2008 08:53:44) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

 

I am running the command

 

php scrubber.php > /tmp/scrub_output.txt &

 

to run this script and output the contents into that file.

 

Here is my output:

 

 while($row=mysql_fetch_assoc($result)){
                if(isset($status)){
                        $backLength = strlen($status) + 1;
                        for($i=0;$i<$backLength;$i++)
                                echo chr(;

                }
                $rowsLeft = $rowTotal-$scrubbedRows;
                $status = "Total Rows: ".$rowTotal." |  Scrubbed Rows: ".$scrubbedRows." |  Rows Left to Scrub:".$rowsLeft." |  Scrub Started on ".$now." ";
                echo $status;

[...]

 

In my output file, I am getting a ton of "^H"  in between each echo. I am echoing BACKSPACES, which I think may be being written to the file as "^H" What is causing this and how can I fix it?

I am trying to limit the file size of my output file. At any point in running this script, there can be hundreds of thousands of rows left to process. I want to simply go to this file and see one sentence of information. I do not need to store an output line for each row of data, I just need the information at the point in time when I open that file.

OH...i see what you are trying to do. if you are trying to show progress, why don't you do a simple progress indicator, like so:

0%                  100%

|||||||||||||||||||||||||

that way you don't need to do any backspace characters

it's a case where you can't have your cake and eat it too i think. the backspaces make it look pretty when it's just a normal output to the terminal...but if you pipe it to a file you will get those ^H characters.

 

the other alternative is to specify the output file as an argument...then you have full control to read, write, and delete the contents of that file

Thanks for the help.

 

Here's the code down and dirty, look good?

 

 $percent = (($scrubbedRows/$rowTotal)*100);
                if(($percent%5) == 0)
                        echo "|";

 

Of course I already echo 0% and 100% within 20 spaces of each other.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.