#190951 - 2008-12-09 11:39 AM
READLINE output
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
I am having a problem reading a file. I have a file that I am trying to read and get it to search for a string in one of the lines. However, the READLINE seems to look at each individual character in the line and thus breaking up what I am looking for.
I have tried to rename the extension of the file to TXT, but I still have the same problem. The only way I can get it to work is to copy the contents of the file into notepad and then save it as a TXT file or if I save it with the same file extension as the original file. When I use either of these methods, the string I am looking for can be found. It does not work i I simply copy the file elsewhere and rename it directly.
I added the command
'Result of first ReadLine: ' @ERROR ' / ' @SERROR ? which someone pointed out to me for another problem and I get the result of Result of first ReadLine: 0 / The operation completed successfully. for the first line that is read, but the last line that is read, comes out as Result of first ReadLine: -1 / Error (317 / 13D) while retrieving error information for FFFFFFFF
This is the sample code I am using:
BREAK ON
CLS
$nul=OPEN(1,"\\server_name\confreuters$\Config\Fichiers_XML\cfg_configuration_default.xml")
'Result of first ReadLine: ' @ERROR ' / ' @SERROR ?
$allow = READLINE(1)
WHILE @ERROR=0
? $allow
$allow = READLINE(1)
LOOP
'Result of first ReadLine: ' @ERROR ' / ' @SERROR ?
close(1)
Normally I wouldn't have the ? $allow in there, but I am using that just to see what is happening, my normal script would read as follows:
BREAK ON
CLS
$nul=OPEN(1,"\\server_name\confreuters$\Config\Fichiers_XML\cfg_configuration_default.xml")
$allow = READLINE(1)
WHILE @ERROR=0
IF iNSTR($allow,@WKSTA)
GOTO PERMIT
ELSE
ENDIF
$allow = READLINE(1)
LOOP
:PERMIT
do what you gotta do here
close(1)
For some reason in the file that is not read properly, the first thing it prints on my screen is a ÿ_ and I have no idea why or where it comes from.
Thanks in advance for any and all help.
|
|
Top
|
|
|
|
#190954 - 2008-12-09 01:03 PM
Re: READLINE output
[Re: Glenn Barnas]
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
If I had to guess, the file you are reading is not regular (ANSI) text. Smells like binary or Unicode...
Open it in Notepad - can you read it? If so, click File / Save As. Note the data format at the bottom of the Save As dialog box - is it Ansi? If not, it won't be a regular text file and while ReadLine will read the data, it won't likely be what you need without conversion.
Glenn
Thanks a lot.
When I went to do my Save As, it shows me the encoding type as Unicode. Never thought about that one. Do you have a solution for a work around to this? Until I hear back, I'm going to scower the forums for a solution.
|
|
Top
|
|
|
|
#190958 - 2008-12-09 01:35 PM
Re: READLINE output
[Re: zdarma]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Don't scower - didn't your mom ever tell you your face might freeze that way?
You could just save the file as ANSI and verify that it works.. (different name, and adjust your script, or back it up first.)
Where did the file come from? Did another file generate it, or was it created and unwittingly saved as Unicode? If it's the latter, just re-save the file as ANSI. If it's generated by an application in Unicode, you'll need to locate a tool or UDF to convert it to a temporary working file for your script. I don't have a suggestion for conversion at the moment, but quick & dirty would be Run 'NOTEPAD filename', use SetFocus('notepad - filename'), and use SendKeys to send "+FA newfilename +EA "
The SendKeys is not verified - you need to send Alt-F, A (File, Save-As), the new filename, Alt-E, A (select Encoding field, set Ansi), and Enter (or Alt-S) to save.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#190961 - 2008-12-09 01:47 PM
Re: READLINE output
[Re: Glenn Barnas]
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
You're right, no scowring. However, some careful searching and reading did net me a solution and gave me the opposite of a scowl. 
The original file is generated by another application and if I change it, I will destroy the configuration of the file and that would be bad, bad, bad. This is the solution I found and it seems to have worked like a charm, if anyone is interested.
BREAK ON
CLS
COPY "\\server_name\confreuters$\Config\Fichiers_XML\toto.xml" "C:\Win32app\Reuters\"
shell '%comspec% /c type "C:\Win32app\Reuters\toto.xml" >> C:\test.txt'
$nul=OPEN(1,"C:\test.txt",2)
$allow = READLINE(1)
WHILE @ERROR=0
$allow = READLINE(1)
IF INSTR($allow,@WKSTA)
GOTO DONE
ELSE
ENDIF
LOOP
GOTO END
:DONE
cls
? "Found it"
GOTO FINI
:END
cls
? "Not Found"
:FINI
close(1)
This is basically what I'm going to use, with some minor modifications to get rid of the copied file and the created file.
|
|
Top
|
|
|
|
#190981 - 2008-12-10 08:35 AM
Re: READLINE output
[Re: Glenn Barnas]
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Thanks for pointing out that I had put a double ">" in my script, guess I was a little overly excited about figuring out a way to make it work, but it doesn't really matter if I do a ">>" or a ">" because at the end of the script, I delete the created files.
The rest of the code that I put in, is there as makrers for me when I was testing how to convert to ANSI, where I would need to put certain actions that needed to be done, if certain items were found in the converted files.
Z
|
|
Top
|
|
|
|
#191039 - 2008-12-11 10:16 AM
Re: READLINE output
[Re: zdarma]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This comes up periodically, for example this post: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=1&Number=118236
In this example we are actually converting from ANSI to Unicode.
The /A and /U CMD switches explicitly control whether output is ANSI or Unicode respectively.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|