Jump to content

query file for contents


Recommended Posts

does anyone know of a way to have autoit query a file for specific contents.

i'd like to run pslist to list and export the contents based on a variable.

$workstation = InputBox ( "title name here", "box contents here.","")

RunWait(@ComSpec & " /c " & 'c:\pstools\pslist.exe \\' & $workstation & " >" & $workstation & ".log", "c:\pstools")

that portion works.

i'd like to have autoit, read the contents of the file i just created to look for the word "update" based on the return code, i can process different procedures. i just dont know how to get it to query the file.

thanks in advance for anyone help.

Keilamym

Link to post
Share on other sites

thanks Joey but i couldn't get it working..

i just opened the file to a window, used the window text options to find the text, then close the file. i think its sloppy but atleast it works.

:">

<{POST_SNAPBACK}>

Sloppy is right! But again, it does work.

Try looking at the help file for the UDF _filereadtoarray()

That way you can run a loop on the resultant array and extract the specific information if found.

#include <file.au3>
Dim $aRecords, $x, $flag = 0, $file = "C:\file.txt"
If Not _FileReadToArray($file,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    If $aRecords[$x] = "Some Text" then
  ; or comment above and use the following line to search for a specific string within the record
  ; If Not StringInStr($aRecords[$x],"Some Text") = "" then
        $flag = 1
        ExitLoop
    EndIf
Next
If $flag = 1 then
    MsgBox(0,"Record: " & $x, $aRecords[$x])
Else
    MsgBox(0,"Error", "Unable to locate string")
EndIf

That was just modified from the help file and should help you along. :lmao:

Make sure to #include <file.au3> at the start of your program otherwise you'll get an Unidentified Function name.

Edit: Put the $flag variable in front of the ExitLoop. Silly mistake.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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