Jump to content

Problem with func. "FileReadLine" in AutoIt Version 3.3.4.0


 Share

Recommended Posts

Hi,

i have a problem with func. "FileReadLine" in AutoIt Version 3.3.4.0

I will open an inuse logfile with "$RC = FileOpen($LOG, 0)" the RetunCode is -1.

AutoIt can not open the inuse logfile.

AutoIt Version 3.3.2.0 or less runs with the same syntax without problems.

Is that a bug or a feature?

Can anyone help?

Link to comment
Share on other sites

I had the same problem at first. After I don't know really what fixed it. But now :D it works.

Maybe reinstall, reboot, I cannot say.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

unclesam,

open an inuse logfile

Could it be a problem with trying for multiple opens on the same file? I know a lot of work went into the File* functions during the 3.3.3.* Beta phase, although obviusly I am not privy to the details:

Please test the ever-loving fuck out of the file functions: FileOpen(), FileClose(), FileRead(), FileReadLine(), FileWrite(), FileWriteLine(), FileGetPos(), FileSetPos() and FileFlush(). A lot of change has gone into those

Perhaps using _FileReadToArray might be a solution for you as it does not rely on you keeping a handle open over a long period. It also gets you the contents nicely arranged in an array so that your code might not have to change too much to manage the new format. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

thanks for the quick responds.

i check it on an other PC - same problem with 3.3.4.0

Less 3.3.2.0 runs without problem

The func. "_FileReadToArray" has the same problem it doesn't work when the file is inuse.

If the file not inuse runs the scipt fine.

The file what I want to open is inuse by an other application not from the script!

Link to comment
Share on other sites

  • 1 month later...

the new version 3.3.6.0 has the same problem. is the file inuse by an other application, AutoIt can not open (read)the inuse file. AutoIT Versions 3.3.2.0 or less runs without problem. Is this bug/featue fixt in the next autoit version?

Link to comment
Share on other sites

  • Moderators

unclesam,

Are you sure? I have just tried to open a file already open in Notepad and Autoit 3.3.6.0 opened it without problem. I tested with both FileOpen and FileRead. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Me too, new version seems to work well!

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

unclesam,

Are you sure? I have just tried to open a file already open in Notepad and Autoit 3.3.6.0 opened it without problem. I tested with both FileOpen and FileRead. :mellow:

M23

You can do that in 3.3.4.0 as well. Notepad does not lock the file. Notepad has issues with an already opened file though.

Try this with 3.3.6.0 (I do not have it at present)

$h_write = FileOpen('test.txt', 1)
;~ FileClose($h_write)
;~ Run('notepad "' & @WorkingDir & '\test.txt"')
$h_read = FileOpen('test.txt', 0)
If $h_read = -1 Then
    FileClose($h_write)
    MsgBox(0, @AutoItVersion, 'Failed to open handle for read')
EndIf

FileDelete('test.txt')

Uncomment the lines and works OK in 3.3.4.0 but fails as is current form.

Link to comment
Share on other sites

  • Moderators

MHz,

Notepad does not lock the file

Thanks for that info - you learn something every day! :mellow:

Now I have tried with other apps, I agree that v3.3.6.0 does NOT open or read already open files.

This was already fixed once in v3.3.5.3 Beta:

AutoIt v3.3.5.3 (Beta) Released

- Fixed: Regression in FileOpen() where it wasn't allowed to open files in read mode if they were already open in write mode

I will open a ticket.

M23

Edit: Ticket raised #1515

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

Hi

I have similar problem like Unclesam, but the other way. I have a logfile ("debug.log") to watch. I read lines over and over again with FileRead, because the program watches the newly appended rows.

But if I open the file with FileOpen("debug.log", 0), the other program can't access it, therefore no new lines are added. This poblem didn't appear in the previous versions of AutoIt.

Is somebody can help me how to open the file for reading, that is not locked to the other programs to writing?

Link to comment
Share on other sites

  • Moderators

Marci and fusion254,

The ticket I raised has been accepted but I do not think any of the Devs have the time at present to work on AutoIt. I am afraid you will just have to wait until the next Beta release. However, given that AutoIt used to behave as you wish, I hope it will not be difficult to fix - just keep your fingers crossed! :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

After spending one day of searching in my new compiled script, I ran over this post. (btw: I read also the HISTORY; but to me it was not obvious that fileread affects me :-) )

OK, now I understood the cause (newer is not always better for all....)

BUT, isn't there a way like calling a strange API/DLL structure to get the same result in 3.3.6.0?

If someone could post a suggestion (or post number) to show how to open a file with Autoit in "shared" mode, I will bow down before him/her.

(ok, some other will tell me: 'wait for the fix', or 'use 3.3.2.0', but for some strange other reasons I can't)

Thanks in advance.

//edit: Oh, I forgot: I'm facing a problem like Marci.

//edit2: I think I got a solution for me: _WinAPI_CreateFile($sFile, 2, 2,6)

OK I need a little rearrange the readfile function but that's ok, so I'm fine with what I found.

very scary: I also tried some sort of Mutex......uuuhahaha to get by. So you see I'm almost open to any suggestion.

Edited by Tankbuster
Link to comment
Share on other sites

@KaFu: Thx, found it already (maybe even in one of your older posts, thx)

@Marci:

Just guessing, that you read a constantly written file (by some other process?) and your Autoit shoudl read it without blocking the other process, correct?

Maybe this will help you:

#include <Array.au3>
#include <WinAPI.au3>

Global $sFile, $hFile, $sText, $nBytes, $tBuffer,$sTextCur,$lastPosition
Dim $aRecods[1]

$sFile = @ScriptDir & '\TEST.LOG'
$lastPosition=0
$lastsize=0
while 1 
    readfile()
    sleep(1000)
wend
_WinAPI_CloseHandle($hFile)

func ReadFile()
    $hFile = _WinAPI_CreateFile($sFile, 2, 2,6)
    $size = _WinAPI_GetFileSizeEx($hFile)
    $Deltasize=$size-$lastsize
    if $Deltasize<=0 Then
        consolewrite("Nothing new to read --- "&@CRLF)
        $sTextCur=""
    Else
    ConsoleWrite("Size:"&$size&@CRLF)
    $tBuffer = DllStructCreate("byte[" & $size & "]")

    _WinAPI_SetFilePointer($hFile, $lastPosition)

    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $Deltasize, $nBytes)
    
    $sTextCur = BinaryToString(DllStructGetData($tBuffer, 1))

    $aRecords=StringSplit($sTextCur,@CR)
    ConsoleWrite('' & $sTextCur)
    $lastPosition=$size
    $lastsize=$size
    
    EndIf

EndFunc

It reads a file in the end you will have something like FileReadLine or _File2Array.

But this is just a guess, maybe it helps you or inspires you for something that works for you.

Here is a batch that will write a simple file for the Autoit Script here:

@echo off
set LOGFILE=TEST.LOG
cls
del %LOGFILE%
:START
echo %date% - %time% >> %LOGFILE%
echo %date% - %time%

if exist STOP.CTL goto STOP
goto START

:STOP
del STOP.CTL
goto end

:END
Link to comment
Share on other sites

  • 5 weeks later...
  • Moderators

TripleDES,

It is actually fixed in 3.3.6.1: :idea:

16th April, 2010 - v3.3.6.1

AutoIt:

Fixed #1515: FileOpen() still opening in exclusive mode in some situations.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...