Sign in to follow this  
Followers 0
willwatters

AutoIT Error file handle invalid.

4 posts in this topic

I use the following code in win 2000 and it works ok but not in XP:

;/* Reusable code to write testing status logs to file

#include "WriteToFile.au3"

;/* Check it test is a pre (0) or post (1) package drop test (assign 0 or 1 to $Post variable)

#include <file.au3>

;/* Check the application/desktop icon exists

$Location=(@DesktopCommonDir & "\CLMS Remote User.lnk")

If Not FileExists($Location) Then

_MyLog($Post, "16", "CLMS Remote Access", "Application/desktop icon does not exist", "")

Exit

EndIf

;/* Launch the application

;Read in the path of a shortcut

$details = FileGetShortcut(@DesktopCommonDir & "\CLMS Remote User.lnk")

$mycommandline = $details[0]& " " & $details[2]

;Launch CLMS Remote Access from desktop

run ($mycommandline,"",@SW_MAXIMIZE)

Sleep(5000)

;Check first screen appears.

WinActivate("Flourish - Clms [ Multiple Setup Support ]","")

If WinExists("Flourish - Clms [ Multiple Setup Support ]") Then

;Do Nothing

Else

_MyLog($Post, "16", "CLMS Remote Access", "CLMS Remote Access failed to open", "")

Exit

EndIf

;....etc

THIS IS THE WriteToFile.au3:

;WriteToFile.au3

Func _MyLog($Post, $TestID, $Area, $Error, $ErrorNumber)

;Writes $psText to my logfile.

$file = FileOpen("C:\Development\vbcommon\LogFile\AutoLab.txt",1)

FileWriteLine($file, $Post & "," & $TestID & "," & $Area & "," & $Error & "," & $ErrorNumber)

FileClose($file)

EndFunc

I get the following error when this code executes/error occurs - FileWriteLine($file, $Post & "," & $TestID & "," & $Area & "," & $Error & "," & $ErrorNumber):

AutoIt Error

Line 0 (File "C:\Development\Autoit\Test16_CLMSRemoteAccess.exe"):

FileWriteLine($file, $Post & "," & $TestID & "," & $Area & "," & $Error & "," & $ErrorNumber)

Error: File handle invalid. Make sure that the FileOpen command succeeded.

Do you know why this is please and what is the code to resolve this:

Share this post


Link to post
Share on other sites



I'll take a guess.. is it possible that the : on the end is doing this

Line 0 (File "C:\Development\Autoit\Test16_CLMSRemoteAccess.exe"):

Share this post


Link to post
Share on other sites

Try checking to see that the file has opened.

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

$file = FileOpen("C:\Development\vbcommon\LogFile\AutoLab.txt",1)
Are you opening this file for writing by another script/process?

Make sure that the file is not locked and you have write permissions to it.

If the file doesn't exist, make sure the directory does, and you have write permissions to it.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
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
Sign in to follow this  
Followers 0