Jump to content

Reading Error Message then Replacing Files


Eambo
 Share

Recommended Posts

Hi Everyone!

I'm just getting into the AutoIt way of things, and I haven't done any programming in quite some time, so forgive me if I sound stupid :-) What I'm wondering is is this possible with AutoIt:

Basically I'm looking to make a script that'll look up an error message in a text file, and download the corresponding errored file and replace it. For example:

All error messages show [ERROR] before them. I would want this file to look up [ERROR], and read the error. So let's give an example:

[ERROR]: Unable to download C:\AutoIt\Eambo'sScript

[ERROR]: Unable to download C:\AutoIt\Eambo\Script2

Okay, so we've found the error. Next up, I'd like it download the errored file and replace it. For example, let's say I have a website:

www.mysite.com/Eambo'sScript

www.mysite.com/Eambo/Script2

So I want to download essentially mysite.com/Eambo'sScript to C:\AutoIt\Eambo'sScript and replace it.

Is this possible? If so, would it be complicated? I'm still working on part 1, I get how to open a folder and find an error, but I'm working from there! :-)

Link to comment
Share on other sites

Post your code.

Look at InetGet()/InetRead() and section in the helpfile Function reference/String management.

EDIT: Welcome to the Autoit scripting world :-)

I think I may have dived in a bit too deep to begin with. I'm going to cut it down to size.

First up: Simply opening the file, finding the error. At the minute I have the following, which is absolutely not functioning :-)

FileOpen("Error.log")
$FindText = "[ERROR]"
$Error = StringRight($FindText, 100000)

I know this is completely wrong, I'm honestly just playing about. But what I'm trying to do here if you can't tell is open up the Error Log, and find the string $FindText. By finding this, we have the start of the error line. I'm then looking to copy that line to a string preferably. One method of doing this I was toying with would be:

- Begin at line 0

- Scan each line

- Find the error

- Copy the line number.

I then want a way to trim this line.

(EG: [ERROR]: Unable to find file C:\Directory\File.exe. I would want to trim this up to Directory\File.exe so as to match up with the online folders, and copy it down.

Any suggestions on what the best method of doing this would be?

Link to comment
Share on other sites

New plan :x

Would this work/Should this work?

#include<file.au3> 

$file = "Error.log"
FileOpen($file, 0)
$i=0

While $i < _FileCountLines($file)
    
    
    $line = FileReadLine($file, $i)
    If StringinStr($file,"[Error]")         Then
        
 msgbox($line)
 
 Else
 
 $i = $i+1
 
 EndIf
 
WEnd
Edited by Eambo
Link to comment
Share on other sites

$FindText = "[ERROR]"
$text = FileRead("Error.log")
$array = StringSplit($text, @CRLF, 1)
For $i = 1 To $array[0]
    If StringInStr($array[$i], $FindText) Then
     MsgBox(0,'Result', 'Line number: ' & $i & @CRLF & 'Line text: ' & $array[$i])
     Exit
    EndIf
Next

Thank you :-) So I'm trying to understand this code (I honestly want to learn!) so hopefully you can help me understand it :-) I understand that we're opening the file and setting the string to search for, however I get slightly lost at the StringSplit. Would you mind showing me what's going on from here? Thank you again, I do appreciate your time.
Link to comment
Share on other sites

So, did you download scite?

If so highlight the key word in your script and press F1 - this will bring up the help file for that function/command what have you.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

sorta, you are setting a full line to a string and then using the for loop you are going from one line to another checking for the string you want find

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Another potentially stupid question :-)

I assume by putting in "Error.log" the script will look in the same folder it exists in? Or do you need to explicitly tell it "Look in this folder"? My reason for asking is that when I compile, build and run the .exe, it's not giving me the MSG output :-(

Edit: So far I've got this, can someone take a look over it and let me know if I've done something stupid? I'm kinda sleepy, and the code for looking up the error doesn't want to play nice at the minute. When I run this it tries to download something, however I don't think it's doing the error lookup so it doesn't know where to find the file.

$ErrorLine = 0
$FindText = "[ERROR]" ; Error Text to Find
$text = FileRead("Error.log") ; Open the Error File
$array = StringSplit($text, @CRLF, 1) ; Make an array, cut it up into lines and search for the full $text Error
For $i = 1 To $array[0] 
    If StringInStr($array[$i], $FindText) Then
     MsgBox(0,'Result', 'Line number: ' & $i & @CRLF & 'Line text: ' & $array[$i]) ;OutPut the Error
     $ErrorLine = $array[$i] ;Set the $ErrorLine to contain the $array
     Exit
    EndIf
Next

$ReplaceErrorText = ''; Replace with nothing
$DownloadLine = StringReplace ($ErrorLine, '[ERROR] ', $ReplaceErrorText); ; Should replace [ERROR] with nothing.

$FileURL = "http://www.website.com/Directory/"
$FileName = $DownloadLine
$FileSaveLocation = FileSaveDialog("Save Location...",$DownloadLine,"All (*.*)") 
$FileSize = InetGetSize($FileURL)
 
InetGet($FileURL,$FileName,0,1)
 
ProgressOn("","")
While @InetGetActive
    $Percentage = @InetGetBytesRead * 100 / $FileSize
    ProgressSet($Percentage,"Downloaded " & @InetGetBytesRead & " of " & $FileSize & " bytes","Downloading " & $FileName)
    Sleep(250)
Wend
ProgressOff()
 
MsgBox(0, "Done","Download Complete!")
Edited by Eambo
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...