Jump to content

AutoIT Error file handle invalid.

Recommended Posts

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", "")



;/* 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)


;Check first screen appears.

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

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

;Do Nothing


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




THIS IS THE 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)



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:

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.")

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

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]

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...