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

read in a file

Status
Not open for further replies.

Matta25

Technical User
Jan 6, 2004
82
0
0
US
I need to have a script open a file then go down to the 4th line and read in the first 10 characters. any ideas of commands to do this?
thanks
 
Here's a script that should work for you. The first three fgets commands are just used to get the file pointer to the fourth line in the file. You'll need to modify the fopen command so that it points to the file you are interested in:

proc main
string sLine
string sValue

if fopen 0 "file.txt" READ TEXT
fgets 0 sLine
fgets 0 sLine
fgets 0 sLine
fgets 0 sLine
substr sValue sLine 0 10
endif
endproc

aspect@aspectscripting.com
 
OK , from that, would this work.

Im not sure how this will go.
Does the script run, then when it gets to it grab the information from that file you need? or does it get it at compile time.

I have done things a different way. I used things like
an include file and commands to define things like -
#define CAPFILE "FRI TEST "

Then in the script it gets that and uses it. But I had initially thought it was when the script was running it went and got that info, so I could therefore have one script but change the details in that include file which was happening automatically. But now I realised that dont work.
Is there a way to do this? or can it ONLY ever get the info before its compiled :(
From that is my only option to get the file to be automatically compiled before ran? can you do this using the compiler at the command prompt ?
 
Anything that is referenced by #define or #include in a script is linked in at compile time. If you run the .was file when you launch Procomm (I'm assuming this is all done from a command line) instead of the .wax file, then Procomm will compile the .was file and get any changes into the new .wax file, which is then executed.


aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top