NightGaunt Posted April 14, 2006 Share Posted April 14, 2006 (edited) Introduction As a quick introduction due to the fact this is my first post. My names Rob and I started using Auto-It a few months ago for a variety of tasks. A great portion of my job is as a proffesional Package Builder; primarily with Wise/Installshield so automation tools are of great assistance to me in a number of areas. I occasionally write in VB but I never really liked it, and VB.Net or C++ can often be an extraordinarily inefficient way of completing the tasks I need to complete. Auto-It seems like a brilliant solution to these issues and I have been using it extensively for a number of projects that have come up. My intention is to join this community as best I can; learn the tool better, and offer advice when I am able to. Start Question The tool I am creating is rather large; most of it works properly but a piece of the Logging is failing. The premise is to read in the log file, and out-put it to a single file so that the logs generated by the command are all combined. Here is the code that is failing for me: While 1 $sServerShareName = FileReadLine($TempServerLog,$n) if $sServerShareName = "" or @Error = -1 then ExitLoop $n = $n+1 $sServerShareNameFriendly = StringReplace ($sServerShareName,"\","") $sServerShareNameFriendly = StringLeft($sServerShareNameFriendly,12) ;MsgBox (0, $sServerShareNameFriendly, $sServerShareName) $TempLog = ("C:\Install\" & $sServerShareNameFriendly & ".txt") _Sharepermissions($sServerShareName, $TempLog) FileOpen($TempLog, 1) FileClose($TempLog) ProcessWaitClose("subinacl.exe") sleep (1000) $n1=2 while 1 $TempLog = StringLower($TempLog) FileOpen($TempLog, 1) $sLineTemp = Filereadline($TempLog,$n1) msgbox(0, $slinetemp, $TempLog) If $sLineTemp = "" or @error = -1 then ExitLoop fileopen($PermissionLog, 1) FileWriteLine($PermissionLog, $sLineTemp) FileClose($PermissionLog) FileClose($Templog) ;FileDelete($TempLog) ;Filemove($TempLog, $LogStorage & "Server_" & $sServerShareNameFriendly & "_.txt") WEnd WEnd The function call is not extraordinarily interesting but for completness... Func _SharePermissions ($ServerName, $Log) Run ('subinacl /outputlog="' & $Log &'" /share ' & $ServerName & " /Display",@DesktopDir,@SW_HIDE) EndFunc My issue is this, the text files that are generated by the subinacl command should be easily text readable. But my output is either "garbage" characters or simply blank. The program never gets past the second line despite the multi-lines of text. Initially I suspected the problem may be the first blank line at the top, but setting the variable to start at the second line still sent me two blank lines. The msgbox was error checking, and the StringLower was used in case some of AutoIt was Case Sensitve and that was causing the issue. Clearly that is not the case; but I wanted to check the avenues I could first. Any assistance would be most appreciated, and because I am trying to learn this tool as best I can pointing and direction would be even more appreciated then a straight answer. Though letting me know how you arrived at the answer will likely also be very helpful. Finally in case it is relevent here is the file I am reading. =============================== +Share =============================== /control=0x0 /audit ace count =0 /perm. ace count =1 /pace =everyone ACCESS_ALLOWED_ACE_TYPE-0x0 Full ControlEdit: I realize I had left out a line that incremented the variable $n1; I have fixed this in the code and it doesn't make a difference, sorry about that a silly catch. Edited April 14, 2006 by NightGaunt "I have discovered that all human evil comes from this, man's being unable to sit still in a room. " - Blaise Pascal Link to comment Share on other sites More sharing options...
MHz Posted April 14, 2006 Share Posted April 14, 2006 Welcome NightGaunt, Well, I'm not sure if I have messed it up or cleaned it up, but I think I have done what i can interpret as what you may want. Either way, you will notice that when I use FileOpen, I do use the handles to the files that it returns. The MsgBox that you were using for debugging was actually blocking the error check as you have to check @error immediately after a function call or store in it in a variable, else the next function clears it. Hopefully it may give you some idea's to fixing your problem. expandcollapse popup$TempServerLog = 'filename here' $handle_TempServerLog = FileOpen($TempServerLog, 0) If $handle_TempServerLog = -1 Then MsgBox(0x10, @ScriptName, 'Read error') Exit EndIf $sServerShareNameFriendly = 'filename here' $TempLog = "C:\Install\" & $sServerShareNameFriendly & ".txt" $PermissionLog = 'filename here' Global $file_open; Allows fileopen to act only once within loop while var is empty While 1 $sServerShareName = FileReadLine($handle_TempServerLog) If @error Then ExitLoop If $sServerShareName = "" Then ContinueLoop $sServerShareNameFriendly = StringReplace($sServerShareName, "\", "") $sServerShareNameFriendly = StringLeft($sServerShareNameFriendly, 12) ;MsgBox (0, $sServerShareNameFriendly, $sServerShareName) $pid = _SharePermissions($sServerShareName, $TempLog) ProcessWaitClose($pid) Sleep(1000) If Not $file_open Then $handle_TempLog = FileOpen($TempLog, 1) If $handle_TempLog = -1 Then MsgBox(0x10, @ScriptName, 'Write error TempLog') ExitLoop EndIf $handle_PermissionLog = FileOpen($PermissionLog, 1) If $handle_PermissionLog = -1 Then MsgBox(0x10, @ScriptName, 'Write error PermissionLog') ExitLoop EndIf $file_open = 1 EndIf While 1 ;$TempLog = StringLower($TempLog) ????? $sLineTemp = FileReadLine($handle_TempLog) ; Do not block @error check with a function here. If @error Then ExitLoop If $sLineTemp = "" Then ContinueLoop MsgBox(0, $sLineTemp, $TempLog) FileWriteLine($handle_PermissionLog, $sLineTemp) WEnd WEnd If $handle_PermissionLog <> - 1 Then FileClose($handle_PermissionLog) If $handle_TempLog <> - 1 Then FileClose($handle_TempLog) If $handle_TempServerLog <> - 1 Then FileClose($handle_TempServerLog) ;FileDelete($TempLog) ;Filemove($TempLog, $LogStorage & "Server_" & $sServerShareNameFriendly & "_.txt") Func _SharePermissions($ServerName, $Log) Return Run('subinacl /outputlog="' & $Log & '" /share ' & $ServerName & " /Display", @DesktopDir, @SW_HIDE) EndFunc Link to comment Share on other sites More sharing options...
NightGaunt Posted April 14, 2006 Author Share Posted April 14, 2006 Ok, I am getting better at understanding this as I work through it. I had to make some modifications, the script you wrote appears to assume only 1 file. Unfortunatly the Function I call basically grabs information from a file I already created that is a compiled list of server names, checks each server and creates a file named after that server as a log file. This part of the script was designed to slap all those existing pieces together in to one big .txt file log (unfortunatly the output of the command always makes 1 file, and overwrites an existing file instead of appending). I made some modifications to your script, much appreciated, but am still running in to an error. While 1 $sLineTemp = FileReadLine($handle_TempLog) If @error Then ExitLoop If $sLineTemp = "" Then ContinueLoop MsgBox(0, $sLineTemp, $TempLog) FileWriteLine($handle_PermissionLog, $sLineTemp) WEnd I think I may be able to figure it out on my own but here is my question. in my original code I had these lines... $sLineTemp = Filereadline($TempLog,$n1) $n1=$n1+1 to read each line of code then go to the next line within a while statement. In your code you just use the code above. If you just set $handle_TempLog = FileOpen($TempLog, 1) and call $sLineTemp = FileReadLine($handle_TempLog) how does the line ever increment past the first line? Do I need to set the $Templog, 1 back to the $n1 I used earlier, or is there a piece I am missing that causes the program to proceed to the next line rather then read the first line forever? "I have discovered that all human evil comes from this, man's being unable to sit still in a room. " - Blaise Pascal Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 14, 2006 Moderators Share Posted April 14, 2006 _FileReadToArray() in beta might make life a bit easier for you Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
NightGaunt Posted April 14, 2006 Author Share Posted April 14, 2006 _FileReadToArray() in beta might make life a bit easier for you Wow, I love it. Makes it much easier, I can do all of it in a few short lines now. However, I did discover what my primary issue was. It may have worked from the start except that Autoit seems to have issues parsing the text when it is presented in Unicode. The Text file saves itself as Unicode by default and output is...ÿþÿþHowever, upon saving it to ANSI on both files I get the proper results. Interestingly if I set the originating file to ANSI and the file that it is reading to to Unicode (the default) I get㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽ഽ匫慨敲尠停啈䕓ⵈㅓ〹就䕎䥔华䥔㴊㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽⼊潣瑮潲㵬砰⼊畡楤⁴捡潣湵⁴〽⼊数浲捡潣湵⁴ㄽ⼊慰散㴠癥牥潹敮ठ䍁䕃卓䅟䱌坏䑅䅟䕃呟偙ⵅ砰ര䘉汵潃瑮潲൬ഊ (no it shouldn't look like this)Hmmm.. I will have to look at my machine settings, maybe Eastern Language Support and double byte characters is messing with Auto-It's ability to read and write data.Thanks to you both for the help, I learned a new script and some more proper error capturing within this program. That by itself is worth all of the trouble. "I have discovered that all human evil comes from this, man's being unable to sit still in a room. " - Blaise Pascal Link to comment Share on other sites More sharing options...
Fossil Rock Posted April 15, 2006 Share Posted April 15, 2006 I have a similiar problem in that AU3 doesn't support UNICODE. I discovered a way around this by using the DOS command TYPE.$File1 = "Example.log"; Saved in UNICODE $File2 = "Example.txt"; Saved in ASNI ; TYPE command converts UNICODE to ANSI Run(@ComSpec & ' /c Type "' & $File1 & '" > "' & $File2 & '"',"",@SW_HIDE)You supply $File1 with your UNICODE file and $File2 with your ANSI output file.This works fine except I needed to change the code page to 1252 (from the default 437) to get the proper output. You might need to change the code page as well.The discussions can be found here Passing variables to DOS and here Characters not being copied correctly Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
MHz Posted April 15, 2006 Share Posted April 15, 2006 I think I may be able to figure it out on my own but here is my question. in my original code I had these lines... $sLineTemp = Filereadline($TempLog,$n1) $n1=$n1+1 to read each line of code then go to the next line within a while statement. In your code you just use the code above. If you just set $handle_TempLog = FileOpen($TempLog, 1) and call $sLineTemp = FileReadLine($handle_TempLog) how does the line ever increment past the first line? Do I need to set the $Templog, 1 back to the $n1 I used earlier, or is there a piece I am missing that causes the program to proceed to the next line rather then read the first line forever?Specifying line mumber in FileReadLine is bad unless you want to just read a certain line only. AutoIt will auto-increment the line number each time you call FileReadLine without line number added. If you specify line number each time, then AutoIt needs to recalculate the line number by reading up to that line number again. So, normally, do not use the line number in FileReadLine. Leave it to AutoIt to manage. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now