kcston Posted January 6 Share Posted January 6 (edited) I'm trying to use "findstr" to search a number of .mxliff files (think of them as text files) for the phrase "RK manufacturer" and display the names of the matched files in MsgBox. But all I get is an empty file. Run(@ComSpec & " /c findstr RK manufacturer \C:\Users\na\Downloads\*.mxliff > C:\Users\na\Downloads\temp.txt") $strFileContent = FileRead("C:\Users\na\Downloads\temp.txt") MsgBox(0,"Files Matched", $strFileContent) Where did I get it wrong in the syntax? Also, when should I use RunWait() instead. THANKS. ss Edited January 6 by kcston Link to comment Share on other sites More sharing options...
Nine Posted January 6 Share Posted January 6 Your findstr seems incorrect. Make sure you use the correct syntax by going in a DOS console and make it work there first. You should use RunWait as it will wait for the result to be completed before going further. Grab the exit code so you know if there is an error in your DOS statement. Put some error handling (checking @error after each statement) in order to find if something goes wrong. FYI. Currently, even if your findstr was correct, Run will not wait for completion of the DOS statement, so the result will always be empty at the time you read the file... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
rsn Posted January 6 Share Posted January 6 If your text file is UTF-16 BE or LE findstr will not find anything. Find won't find if the file is UTF-16 BE. Link to comment Share on other sites More sharing options...
ioa747 Posted January 6 Share Posted January 6 (edited) ... or you can using the _FileListToArray() function ! with combination of _FileReadToArray Edited January 6 by ioa747 Link to comment Share on other sites More sharing options...
kcston Posted January 7 Author Share Posted January 7 (edited) Thanks for the quick comments. I'm still new to AutoIt so please bear with me. For testing, I have created the following two files in the \Downloads directory. 1.mxliff (1-line content: <target>RK manufacturer available</target>) 2.mxliff (1-line content: <target>RK manufacturer not available</target>) At the command prompt of my Windows 11, the following works. findstr manufacturer C:\Users\na\Downloads\*.mxliff > C:\Users\na\Downloads\temp.txt temp.txt is produced and it contains the following content: C:\Users\na\Downloads\1.mxliff:<target>RK manufacturer available</target> C:\Users\na\Downloads\2.mxliff:<target>RK manufacturer not available</target> However, when put into AutoIt, the following code does not seem to work. No temp.txt is produced and no error detected. Msgbox shows empty content. RunWait(@ComSpec & " findstr manufacturer C:\Users\na\Downloads\*.mxliff > C:\Users\na\Downloads\temp.txt") If @error Then MsgBox(0,"Error",@error) Else $strFileContent = FileRead("C:\Users\na\Downloads\temp.txt") MsgBox(0,"File", $strFileContent) EndIf What else can I try? Edited January 7 by kcston Link to comment Share on other sites More sharing options...
Nine Posted January 7 Share Posted January 7 Here the way with adding error handling : Local $iExit = RunWait(@ComSpec & " /c findstr MsgBox C:\Apps\AutoIt\*.au3 > C:\Apps\Temp\temp.txt") If @error Or $iExit Then Exit MsgBox(0,"Error RunWait",@error & "/" & $iExit) Local $strFileContent = FileRead("C:\Apps\Temp\temp.txt") If @error Then Exit MsgBox(0,"Error FileRead",@error) MsgBox(0,"File", $strFileContent) FileDelete("C:\Apps\Temp\temp.txt") “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
rsn Posted January 9 Share Posted January 9 I poked around some and found this to work (assuming you're working out of your user profile): #include <FileConstants.au3> $sFilePath = @UserProfileDir & "\Downloads\temp.txt" $iPID = Run(@ComSpec & ' /c findstr "manufacturer" ' & @UserProfileDir & '\Downloads\*.mxliff > ' & $sFilePath) ProcessWaitClose ($iPID) If @error Then MsgBox(0,"Error",@error) Else $hFileOpen = FileOpen ($sFilePath , $FO_READ) $strFileContent = FileRead($hFileOpen) If @error Then MsgBox(0,"Error",@error) Exit EndIf FileClose($hFileOpen) MsgBox(0 ,"File" , $strFileContent) EndIf Link to comment Share on other sites More sharing options...
kcston Posted January 9 Author Share Posted January 9 (edited) Somehow already the way I forgot to include the /c switch before findstr. My final version shown below works fine. RunWait(@ComSpec & " /c findstr /i /c:" & Chr(34) & $strPhrase & Chr(34) & " " & Chr(34) & $strFile & Chr(34) & " > C:\Users\na\Downloads\temp.txt") Thank you all for the help. Much appreciated. Edited January 9 by kcston 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