zaxbysauce Posted August 24, 2020 Share Posted August 24, 2020 Morning, I am working on a multi-layered AutoIt solution to automate the installation of several different pieces of healthcare software. One of them uses a jboss vault and I need to capture specific output from some batch files to be put in the standalone.xml file. This output is always between the strings in my code below and is 3-4 lines long. Here is what I have done so far. 1. Run the batch file and send output to a text file 2. Read from the text file using StringBetween to grab the section I need. Now I need to take that section represented in an Array, and convert it to a string so that I can then insert it into the standalone.xml file. See some code snippets below and if there is any more information you need please let me know. Thanks! P.S. - I have messed with _ArrayToString but can't seem to get it to output anything. Func Read() Local $sFileName = 'C:\drive\log.txt' Local $hFileOpen = FileOpen($sFileName, $FO_READ) Local $sFileRead = FileRead($hFileOpen) Local $aFileRead = _StringBetween($sFileRead, "<vault>", "</vault>") If @error Then Exit MsgBox(16, "Error", "String not found") _ArrayDisplay($aFileRead, "Vault") FileClose($hFileOpen) EndFunc Link to comment Share on other sites More sharing options...
Jury Posted August 24, 2020 Share Posted August 24, 2020 StringRegExp directly outputs an array of results Link to comment Share on other sites More sharing options...
Nine Posted August 24, 2020 Share Posted August 24, 2020 Can you show the _ArrayDisplay result. And give us an example of the XML file you want to create from the array. “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 Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
markyrocks Posted August 24, 2020 Share Posted August 24, 2020 I wrote this in about 5 min as a response to a different thread months ago. Not sure if it will help you or if it even works. Func ArrayToString($array) Local $temp for $x=1 to UBound($array)-1 $temp&=$array[$x] & " " Next Return $temp EndFunc Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Zedna Posted August 25, 2020 Share Posted August 25, 2020 I use this wrapper (to return string instead of array): Func StringBetween($sString, $sStart, $sEnd) $sReturn = _StringBetween($sString, $sStart, $sEnd) ;, -1, 1) If @error Then Return '' Return $sReturn[0] EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
zaxbysauce Posted August 25, 2020 Author Share Posted August 25, 2020 6 hours ago, Nine said: Can you show the _ArrayDisplay result. And give us an example of the XML file you want to create from the array. Sure thing. So the value in Row 0 Col 0 is the correct value when displaying the array from my original snippet. I need to take this value and convert it into a string so that it can be inserted into a particular spot in the xml file. My plan is to just use a FileRead similar to the code I have below to insert this line into the xml. The XML generated by the initial install will always have the same values in it so while its clunky it doesn't have to be particularly dynamic to get the job done. If there is a way to do a StringReplace between two strings though that would work even better. Thanks! $File= "C:\drive\autologin.reg" $FileContent=FileRead($File,FileGetSize($File)) $Find= "CHANGEME" $Replace= $sAcct $FileContent=StringReplace($FileContent,$Find,$Replace) FileDelete($File) FileWrite($File,$FileContent) Link to comment Share on other sites More sharing options...
zaxbysauce Posted August 25, 2020 Author Share Posted August 25, 2020 1 hour ago, Zedna said: I use this wrapper (to return string instead of array): Func StringBetween($sString, $sStart, $sEnd) $sReturn = _StringBetween($sString, $sStart, $sEnd) ;, -1, 1) If @error Then Return '' Return $sReturn[0] EndFunc Amazing work. That's exactly what I needed to solve my problem. See my snippet below for the final solution I used and just verified as working. Thanks! Local $sFileName = 'C:\drive\jboss.txt' Local $hFileOpen = FileOpen($sFileName, $FO_READ) Local $sFileRead = FileRead($hFileOpen) $sStart = "<vault>" $sEnd = "</vault>" $jboss1 = StringBetween($sFileRead, $sStart, $sEnd) Local $sFileName = 'L:\jboss-eap-6.4-TC2POE\standalone\configuration\standalone.xml' Local $hFileOpen = FileOpen($sFileName, $FO_READ) Local $sFileRead = FileRead($hFileOpen) $sStart = "<vault>" $sEnd = "</vault>" $jboss2 = StringBetween($sFileRead, $sStart, $sEnd) _ReplaceStringInFile($sFileName, $jboss2, $jboss1) 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