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!

Writing text to the top line of a file

Status
Not open for further replies.

cryptotech

Technical User
Nov 9, 2007
26
US
How would I fputs my text on the top line of a text file each time, shifting the previous lines down?

When I append a text file using fputs or fwrite, I want the next line appended on the top line, not the bottom.

In other words, each successive string added to the text file is added to the top line of the text file and the previous lines are shifted down ( the first line written is at the bottom line of the file and the most recent line is always the top line) Text written could be different lengths.

I've tried different combinations of fseek, fwrite, fputs and can not achieve it.

thanks for any suggestions,


 
I figured it out...it's cheezy, but it works...

filetoclip text "C:\...abc.txt" - copy the file to windows clipboard
fopen 0 "C:\...abc.txt" create text - writes over the existing file
fputs 0 xyz - writes the string
fclose 0
cliptofile text "C:\..abc.txt" append - appends the original text underneath the latest addition.

 
The finsblock command is needed when adding text to an existing file. I figured I would have something like this on my site, but looks like the closest I have is a script that shows how to add text to the end of a line. You can find it here if interested, hopefully it makes sense if you want to try to use similar logic in your script:


 
I've been using the capturstr command, but I can't get it to insert the text at the point I want it. I use pauses, wait, etc., but the text is never inserted where I want it. For example, I want to say "ERROR TABLE" then do the command that lists the errors. The above suggestions seem to address appending text to the beginning or end. Will they work as well for inserting text at specific points?
Thanks.
 
The previous commands mentioned in the thread are for a text file that already exists, whereas you are wanting to write a string to a capture file and then capture additional text so I don't believe they would work for you. My initial guess would be that one of the capture options might be causing issues with the text formatting. If you select the Options | Data Options | Setup Files menu item within Procomm and click the Setup button, what options are chosen?

Another possibility could be that the capturestr command is issued prior to there being any text in the scrollback buffer. The way the buffer (and the capture file) works is that no data is captured until at least one line of data scrolls off the screen or the screen is cleared.

 
The setup is set to "write text as it appears on screen".
My problem has got to be with what gets written first, the buffer or my capturestr commands.
 
Yes, here's a sample of what I'm trying to do:

string szLOGFILE = "ERROR_LOG.txt"
set capture file szLOGFILE
set capture query off
capture on
capturestr "ERROR LOG^M^M"
capturestr " "
transmit "DIAG^M"

capturestr "---------------- ERROR TABLE ---------------------------------"
capturestr " "
transmit "li errh ; ; ;^M"
waitfor "%"
capturestr "---------------- TRUNK ERRORS --------------------------------"
capturestr " "

transmit "li exc tr ; B ;^M"
waitfor "%"

capturestr "---------------- TEMPERATURE ---------------------------------"
capturestr " "
transmit "li temp^M"
waitfor "%"

capturestr "------------ TDM & SOFTWARE ERRORS AND STATUS ----------------"
capturestr " "
transmit "LI ERRORS ERROR 0113 C^M"
waitfor "%"
transmit "LI ERRORS HD^M"
waitfor "%"
transmit "LI ERRORS MEMORY^M"
waitfor "%"
transmit "LI ALARMS T1^M"
waitfor "%"
capturestr "********************************************************"
capturestr "END OF LOG"

(continues...)

Thanks.
 
I apologize for taking so long to get back to this. Can you send me a sample capture log so I can see where/how the strings from the capturestr command are appearing or not appearing?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top