jfitty Posted October 24, 2009 Share Posted October 24, 2009 Hi all, Is it possible to run a command using StdoutRead to capture the output, then insert that straight into an array? I know I could send the output of the command to a text file and use _FileReadToArray, but I would rather the output go straight to an array Thanks in advance Link to comment Share on other sites More sharing options...
Mat Posted October 24, 2009 Share Posted October 24, 2009 What character do you want to split the array on? new line? $sText = StdoutRead (...) $aArray = StringSplit ($sText, @CRLF) Thats a simple way to do it. Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Codeflakes Posted November 4, 2009 Share Posted November 4, 2009 What character do you want to split the array on? new line? $sText = StdoutRead (...) $aArray = StringSplit ($sText, @CRLF) Thats a simple way to do it. Mat Only issue is with non-standard characters - any simple fix for this? (I take it that we're talking an ANSI/UNICODE issue?) #include <Array.au3> #include <Constants.au3> Local $result DirCreate(@DesktopDir & "\Test\Torré") $pid = Run(@ComSpec & " /c dir /B ", @DesktopDir & "\Test", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $result &= StdoutRead($pid) If @error Then ExitLoop Wend $array = StringSplit($result, @CRLF, 1) _ArrayDisplay($array) Link to comment Share on other sites More sharing options...
GEOSoft Posted November 4, 2009 Share Posted November 4, 2009 $aArray = _Array_CreateFromString(StdOutRead($Run)) If NOT @Error Then ;;Do whatever with the array EndIf Func _Array_CreateFromString($sStr) If FileExists($sStr) Then $sStr = FileRead($sStr) If NOT $sStr Then Return SetError(1);; Empty strings not allowed Local $aRtn = StringRegExp($sStr, "(?i)(?m:^)(.*)(?:\v|$)", 3) If @Error Then Return SetError(2) ;; RegExp failed Return $aRtn EndFunc ;<===> _Array_CreateFromString() George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
cherdeg Posted November 4, 2009 Share Posted November 4, 2009 (edited) Just do it like the pros do Only issue is with non-standard characters - any simple fix for this?Yep: #include <Array.au3> #include <Constants.au3> Local $result DirCreate(@DesktopDir & "\Test\Torré") $pid = Run(@ComSpec & " /c dir /B ", @DesktopDir & "\Test", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $result &= StdoutRead($pid) If @error Then ExitLoop Wend $array = StringSplit(StringStripWS($result, 8), @CRLF, 1) MsgBox("", "String", "Before conversion: " & @CRLF & @CRLF & $array[1]) $output_comspec_oem2ansi = _OEM2ANSI($array[1]) MsgBox("", "String", "After conversion: " & @CRLF & @CRLF & $output_comspec_oem2ansi) Func _OEM2ANSI($what) $ret = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $what, 'str', '') Return $ret[2] EndFunc ;==>_OEM2ANSI Edited November 4, 2009 by cherdeg Link to comment Share on other sites More sharing options...
Codeflakes Posted November 4, 2009 Share Posted November 4, 2009 Just do it like the pros do Yep: #include <Array.au3> #include <Constants.au3> Local $result DirCreate(@DesktopDir & "\Test\Torré") $pid = Run(@ComSpec & " /c dir /B ", @DesktopDir & "\Test", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $result &= StdoutRead($pid) If @error Then ExitLoop Wend $array = StringSplit(StringStripWS($result, 8), @CRLF, 1) MsgBox("", "String", "Before conversion: " & @CRLF & @CRLF & $array[1]) $output_comspec_oem2ansi = _OEM2ANSI($array[1]) MsgBox("", "String", "After conversion: " & @CRLF & @CRLF & $output_comspec_oem2ansi) Func _OEM2ANSI($what) $ret = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $what, 'str', '') Return $ret[2] EndFunc ;==>_OEM2ANSI Hey Cherdeg, Kool - works great thanks Codeflakes Link to comment Share on other sites More sharing options...
cherdeg Posted November 4, 2009 Share Posted November 4, 2009 Kool - works great thanksYou're welcome! If I can help, which happens not to often, I do. 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