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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File NOT!! end of file

Status
Not open for further replies.

joet7878

Programmer
Aug 16, 2001
10
AU
Was wondering if anyone here could help out..
Im trying to get the script to read from one file named host.txt then while NOT feof run a function called TSERVER which goes and reads another file called TSERVER.txt. The problem is that when it finishes reading the Tsrever file it goes bacm to proc main thinking that the file is now eof for host.txt ...
The script I made below...

Can anyone help ou please ..Im going mad..

************************************************
proc main


string Fname = "host.txt" ;name cannot be altered
string Fname2 = "tserver.txt" ;name cannot be altered
string linebuffer
string CapName = "Applications.cap"
string linestring



usermsg linestring

if fopen 0 Fname READ TEXT ;open file for read only
fseek 0 0 1
while not feof 0 ;loop while not end of file
fgets 1 LineString
fgets 0 linebuffer ;get host name from file
pause 2
dial TELNET linebuffer ;establish telnet session
while $dialing ;loop while establishing telnet session
endwhile

if $carrier ;if session established
waitfor "login: " forever ;login section
transmit "genesys^m" ;transmitting LOGON
waitfor "password: " forever
transmit "genelabs^m" ;transmitting PASSWORD

usermsg "about to run TSERVER FUNCTION"
pause 1
Call TSERVER














usermsg "ran TSERVER FUNCTION"
usermsg linebuffer
pause 1
transmit "exit^m"
pause 1

else
errormsg "Connection Not Establised To %s." linebuffer
endif
endwhile
else
errormsg "File Not Found"
endif
capture off
endproc



func TSERVER : string ; Must include return type!



string Fname = "host.txt"
string fname2 = "tserver.txt"
string sztext
string CapName = "Applications.cap"


fopen 0 fname2 READ TEXT


while not feof 0

set capture file CapName ; Set name of capture file.
capture on ; Open up the capture file.

fgets 0 sztext

transmit "cd^m"
transmit "cd logs^m"
pause 1

transmit "ls -lrt *"
transmit sztext
transmit "*^m"
pause 2


endwhile


return fname2


 
In your TSERVER function change the fileID to an integer
value other than zero. You have opened your initial file
(host.txt) with a fileID of 0 then you open your second file
(tserver.txt) with a fileID of 0. In the TSERVER function
change the fileID of fopen, feof, and fgets commands to 1.

Also, you will need to close (fclose 1) tserver.txt before
exiting the function.

Let me know if this works or if you need more info.

Matt
 
In this procedure, you are calling the procedure TSERVER during the "while" process. It could be, (not sure about this) that because you are using the same file ID for "fopen 0 FNAME2 read text", that the procedure is getting confused over the file IDs.

I this is the whole procedure, I do not understand where the "fgets 1 LineString" fits in. There is no file open with the ID no. 1.

Try changing the file ID to 2 in your sub routine as follows:
fopen 2 fname2 READ TEXT
while not feof 2
set capture file CapName ; Set name of capture file.
capture on ; Open up the capture file.
fgets 2 sztext

and see if that clears up the problem.
Robert Harris
Communications Advantage
 
Thanks alot for your help ..it worked perfectly...

NOW!! to try and open a file to write the correct information to in a specific format...!!
If you have any pointers it would be very appreciated..Beer is on the way for both of you if you ever get to Melb.

Thx JT
 
Hi JT,

You can write to a file by opening it in any of the following modes:

fopen 0 fileName write
fopen 0 fileName readwrite
fopen 0 fileName create
fopen 0 fileName append
fopen 0 fileName readappend

A file assumes readwrite mode when opened with create.
When opened under write, readwrite, append, or readappend
and the file does not exist then the file is created
automatically. All modes can be opened with the optional
parameter TEXT as follows:

fopen 0 fileName write text

This optional parameter only affects the fgets and fputs
commands. TEXT strips line feeds and return/line feeds
from the fgets commands and appends return/line feeds to
the fputs command.

I'm not sure if this answered you question completely. I'm
a little unclear what you mean when you say "...in a
specific format...!!" I would suggest playing around with
the fputs, fputc, fwrite, and fstrfmt commands and see if
you can't get your desired output.

Hope this helps.

Matt





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top