Jump to content

FileOpen Bug? Would very much appreciate expert assistance


Recommended Posts

*edit: sorry about the stupid title repeat :whistle:

Hello all!

First time caller, long time listener.. heh

I'm having problems with the FileOpen("filename", 1) function.

I would happily post my entire script except that it is about 6 pages in length so I apologize for not doing so, however the problem is only with the logg function, so this should be adequate.

I will instead paraphrase it down to the key functions that are being called.

The purpose of this script is to configure a bunch of stuff as a domain tech and then reboot as the user and finish with the user specific configuration.

The problem is simple, but is confusing the hell out of me....

When the computer is rebooted and the autoit script is re-launched, the log file that I create gets erased and all new information is overwriting the old.

Here is the example script:

#Include<file.au3>

While 1
    $rebooted = IniRead ( @ScriptDir&"\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0 )
    if $rebooted=1 Then
        BEGIN()
    EndIf
WEnd

Func BEGIN()

    $rebooted = IniRead ( @ScriptDir&"\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0 ) 

    if $rebooted=0 Then
           //Commented: Do a bunch of tech config stuff
          logg("Various tech information to be recorded")
          logg("Various tech information to be recorded2")
           //*Reboot and login as user automatically

            elseif $rebooted=1 Then
               //*Do second part of setup here
        logg("Record various information about user setup")    ;for some reason this is replacing the tech info previously logged!?!?
        logg("Record various information about user setup2")
        EndIf

EndFunc

Func logg($sLogMsg)
    _FileWriteLog ( "\\zipperlock\imaging\ImageLogs\"& @ComputerName & "_Image.log", $sLogMsg )
EndFuncoÝ÷ Ù*0éí+"±Ú'zØ^W­«l¥vƲ²¶§X¤{m4ïNö×]8ÛMÕj¸¨ºË^r§~æjبÚz·¢·^wm4ïNö×]8Û]Õj¸¨ºË^r§~æjبÚz·¢·^wm´Ó½;Û]tãm·Eç(­ÛÚ®*.²)ߢ¹¶*'iº.¶ë®Ç­º´Ó½;Û]tãnwEç(­ÛÚ®*.²)ߢ¹¶*'iº.¶ë®Ç­ºË^iÛayø§È^vèvç-8Òز0³m4ïNö×]8ÛmÑyÊ+vö«¬wè®f­Ún­ºÇ«±ën§m4ïNö×]8ÛÑyÊ+vö«¬wè®f­Ún­ºÇ«±ën§`^~Þ­æè¢ÛazZ Â¥vÈhÂØb³m4ïNö×]8ÛMÕj¸¨ºË^r§~æjبÚz·¢·^wm4ïNö×]8Û]Õj¸¨ºË^r§~æjبÚz·¢·^we¡jÒ¢}ý¶éÝz»-jwb³r¶W¢±è­êÛz)àz¶¬yÚ+ßÚÞr·µçwô§½ë-­yÛaxX¥yjâµâèû§rب0z÷«¶¬~éܶ*'¢yrºÇ¬)^:§Ó~¬.jØu§¢·bh¶¡zZ_W¬k+815

So really thats it in a nutshell... I'm not using any other log function and nowhere else in the script is the log changed or opened or closed or anything. The only function that has anything to do with the log file is the logg() function.

Again I very much appreciate any assistance on this one as I'm completely brain dead by now and frustrated as hell.

Posted Image

Edited by bobsyuruncle
Link to comment
Share on other sites

Hey,

Welcome to the forum. Hope you enjoy your stay.

After looking at your script and seeing that your words are over written, I have added a @CRLF which makes a new line. I am not sure if it will solve your problem, but try this:

#Include <file.au3>

While 1
    $rebooted = IniRead(@ScriptDir & "\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0)
    If $rebooted = 1 Then
        BEGIN()
    EndIf
WEnd

Func BEGIN()

    $rebooted = IniRead(@ScriptDir & "\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0)

    If $rebooted = 0 Then
         ;/ / Commented: Do a bunch of tech config stuff
        logg("Various tech information to be recorded" & @CRLF)
        logg("Various tech information to be recorded2" & @CRLF)
         ;/ / * Reboot And login as user automatically

    ElseIf $rebooted = 1 Then
        ; / / * Do second part of setup here
        logg("Record various information about user setup" & @CRLF)    ;for some reason this is replacing the tech info previously logged!?!?
        logg("Record various information about user setup2" & @CRLF)    ; The @CRLF will add a new line
    EndIf

EndFunc   ;==>BEGIN

Func logg($sLogMsg)
    _FileWriteLog("\\zipperlock\imaging\ImageLogs\" & @ComputerName & "_Image.log", $sLogMsg)
EndFunc   ;==>logg

I also tidied your script a bit.

BTW, my Grandad is called Bob for short :whistle:

-James

Link to comment
Share on other sites

  • Developers

Have you tested it with the posted script ?

I seriously doubt that the posted script would have this issue ....

:whistle:

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Hey,

Welcome to the forum. Hope you enjoy your stay.

After looking at your script and seeing that your words are over written, I have added a @CRLF which makes a new line. I am not sure if it will solve your problem, but try this:

@James, _FileWriteLog() already adds the @CRLF for you ....

:whistle:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hey,

BTW, my Grandad is called Bob for short :whistle:

-James

Thanks for the response, I am testing it now and should know in about 30 minutes: "when the image process is complete"

I am however using your idea in a slightly different manner since it would be a royal pain to add that to each of the 100 or so logg commands, so I instead did this which should have the same effect:

Func logg($sLogMsg)
    _FileWriteLog ( "\\ziplock\itcsimaging\ImageLogs\"& @ComputerName & "_Image.log", $sLogMsg & @CRLF )
EndFunc

Instead of yet another post I'll just edit this one with the results when the imaging process is completed.

Also, something of note in case I hadn't been clear on this before.... The logged messages are only being overwritten after the reboot.

Link to comment
Share on other sites

I haven't looked closely at your scipt but the one thing that looks dodgy is the iniread bit. Iniread returns a string so setting 0 as the deafult is likely to cause problems, and comparing a string to 0 or 1 will not give the result you expect.

maybe you could say

$val = IniRead(@ScriptDir & "\dfsimage.ini", "Runtime, Do not Change", "rebooted", "0")

$rebooted = Execute($val)

BTW I would prefer reading your posts if you removed that bloody animation, or put something a bit more pleasant there.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I haven't looked closely at your scipt but the one thing that looks dodgy is the iniread bit. Iniread returns a string so setting 0 as the deafult is likely to cause problems, and comparing a string to 0 or 1 will not give the result you expect.

maybe you could say

$val = IniRead(@ScriptDir & "\dfsimage.ini", "Runtime, Do not Change", "rebooted", "0")

$rebooted = Execute($val)

BTW I would prefer reading your posts if you removed that bloody animation, or put something a bit more pleasant there.

Apologies... I overparaphrased the code for that part. The actual code is about 1052 lines of code with only the log function not working properly.

The iniread and write parts are working great actually.

The script performs all user functions as it is supposed to and only does the reboot function once as it should

what actually happens in the original code is more like:

#Include<file.au3>

While 1
    $rebooted = IniRead ( @ScriptDir&"\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0 )
    if $rebooted=1 Then
        BEGIN()
    EndIf
WEnd

Func BEGIN()

    $rebooted = IniRead ( @ScriptDir&"\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0 ) 

    if $rebooted=0 Then
           //Commented: Do a bunch of tech config stuff
          logg("Various tech information to be recorded")
          logg("Various tech information to be recorded2")
           //*Reboot and login as user automatically
        SplashTextOn ( "Waiting", "Beginning Reboot Sequence ", 300, 30, 90, 30)
        sleep(5000)
        IniWrite ( @ScriptDir&"\dfsimage.ini", "Runtime, Do not Change", "rebooted", 1 )
        logg("computer rebooted for user config part")
        sleep(3000) ;time for splash text to show
        Shutdown (6) ;force shutdown and reboot
        sleep(30000) ;not completely necessary except to prevent script from starting the reboot part too soon

            elseif $rebooted=1 Then
             IniWrite ( @ScriptDir&"\dfsimage.ini", "Runtime, Do not Change", "rebooted", 0 )
               //*Do second part of setup here
        logg("Record various information about user setup")    ;for some reason this is replacing the tech info previously logged!?!?
        logg("Record various information about user setup2")
        EndIf

EndFunc

Func logg($sLogMsg)
    _FileWriteLog ( "\\zipperlock\imaging\ImageLogs\"& @ComputerName & "_Image.log", $sLogMsg )
EndFunc

After spending about two ridiculously long hours on troubleshooting this prior to posting here on the forum, the picture is exactly how I feel... Plus I only posted it once on the first post :whistle:

Here's your image replacement per request of Martin

Posted Image

Edited by bobsyuruncle
Link to comment
Share on other sites

Apologies for being wrong about the return from Iniread, I am too used to another language where 123 is not equal to "123".

But are you saying you still have a problem?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Apologies for being wrong about the return from Iniread, I am too used to another language where 123 is not equal to "123".

But are you saying you still have a problem?

Yes,

I just finished testing Neotronix's idea and that had no effect towards the problem.

Logging still looks exactly the same as before actually. I think the autoit help mentions that the @CRLF is inserted automatically anyways.

I don't really know what else to try or even the reason fileopen isn't appending to the file on reboot.

Link to comment
Share on other sites

  • Developers

Looks like you haven't seen my posts in this thread yet... :whistle:

Are you sure there is no other batch "thing" running that makes the file empty or deletes it during reboot?

Have you tried writing it to the local disk to see whats happening ? (c:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Looks like you haven't seen my posts in this thread yet... :whistle:

Are you sure there is no other batch "thing" running that makes the file empty or deletes it during reboot?

Have you tried writing it to the local disk to see whats happening ? (c:)

I promise you the ONLY function that touches that directory or file in ANY way shape or form is:

Func logg($sLogMsg)
    _FileWriteLog ( "\\ziplock\itcsimaging\ImageLogs\"& @ComputerName & "_Image.log", $sLogMsg)
EndFuncoÝ÷ Ù8^­è¬axÇ«zj-.râé)ࢹ¨v'òxÅÇ©µú+¶¢,+×ا·uû§rبËajÖ¥jür©ë^+¥ªÚµç_²)è§ø¥x"XhÁëÞ®Ö¤{*.­×º"¾'^j»ZÛ^²Ö§¢Ø^®º.Ü"¶·öZj]ýv*ÞrÚ+Ê)ìµæ¡ûazw­Â䥫ajwkz+µ¶)Ún­ßI¢­Øh±êÞ²ém±8^µé©~éܶ*'Â)e$)jëh×6;~ Func logg($sLogMsg)
;~  _FileWriteLog ( "\\ziplock\itcsimaging\ImageLogs\"& @ComputerName & "_Image.log", $sLogMsg)
;~ EndFunc
Func logg($sLogMsg)
    _FileWriteLog ( @ScriptDir& "\"&@ComputerName & "_Image.log", $sLogMsg)
EndFunc
Link to comment
Share on other sites

Update:

Local file completed the log successfully and without overwriting the old logfile.

Which means that for whatever reason the FileOpen function does not append correctly when used over a network location.

Any idea why this might be happening?

In the mean time I think I'll program the script to save everything locally and then just copy the final log file to the network share.

Link to comment
Share on other sites

  • Developers

Update:

Local file completed the log successfully and without overwriting the old logfile.

Which means that for whatever reason the FileOpen function does not append correctly when used over a network location.

Any idea why this might be happening?

In the mean time I think I'll program the script to save everything locally and then just copy the final log file to the network share.

mmm.. it just doesn't make sense to me that a reboot would cause the fileopen with append to fail.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

mmm.. it just doesn't make sense to me that a reboot would cause the fileopen with append to fail.

Thats exactly what I thought when I saw the completed log file with no errors....

I can't figure why a reboot only affects append over a network share, but not on the local disk.

At least now I have something thats 'functional' to some degree.

Thanks for your help... best as I can tell, there must be a bug in autoit related to fileopen and the network share.

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