BigAl Posted January 8, 2015 Share Posted January 8, 2015 Hello I have a small app which runs some machine configuration, stops and disables taks etc and outputs the STDOUT into a variable, then using StringRegExpReplace I remove the blanks lines from the output and then display the this in an Edit control. This works in that it will show me the entire output but I only want to display upto the first 3 lines in my Edit Control. I've googled a few option but not really sure what would be the best way to go about it. I've posted a snippet below which shows the task stopping and how i remove the blank lines Local $superstop = Run(@ComSpec & " /c " & 'sc stop "' & "SysMain" & '"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($superstop) $superout = StdoutRead($superstop) $superoutNBL = StringRegExpReplace(StringRegExpReplace($superout, "(\v)+", @CRLF), "\A\v|\v\Z", "") GUICtrlSetData($Output, GUICtrlRead($Output)& @CRLF & @HOUR & ":" & @MIN & ":" & @SEC & " " & "$superoutNBL$") Any help would be appreciated. Link to comment Share on other sites More sharing options...
Solution mikell Posted January 8, 2015 Solution Share Posted January 8, 2015 This should work $superoutNBL = StringRegExp($superout, '(?m)(^.+)\s*\R?', 3) ; skip blank lines $3lines = $superoutNBL[0] & @crlf & $superoutNBL[1] & @crlf & $superoutNBL[2] Msgbox(0,"", $3lines) Link to comment Share on other sites More sharing options...
jguinch Posted January 8, 2015 Share Posted January 8, 2015 Or this : $sOutput = StringRegExpReplace($superout, "(?s)(\N+(\R+|$)){1,3}\K.*", "") $3lines = StringRegExpReplace($sOutput, "\R{2,}", @CRLF) ConsoleWrite($3lines) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted January 8, 2015 Share Posted January 8, 2015 jguinch, your expression doesn't remove a possible leading blank line Link to comment Share on other sites More sharing options...
BigAl Posted January 8, 2015 Author Share Posted January 8, 2015 Thanks very much for the replies, mikell your solution worked a treat. Thanks again Link to comment Share on other sites More sharing options...
mikell Posted January 8, 2015 Share Posted January 8, 2015 And why not this most simple all-in-one ? $3lines = StringRegExpReplace($superout, '(?s)\s*(\V+\R)\s*(\V+\R)\s*(\V+\R).*', "$1$2$3") Msgbox(0,"", $3lines) 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