Sign in to follow this  
Followers 0
BigAl

Display only upto 3 lines from output

6 posts in this topic

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.

 

Share this post


Link to post
Share on other sites



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)

Share this post


Link to post
Share on other sites

jguinch, your expression doesn't remove a possible leading blank line  ;)

Share this post


Link to post
Share on other sites

Thanks very much for the replies, mikell your solution worked a treat.

Thanks again

Share this post


Link to post
Share on other sites

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)

Share this post


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
Sign in to follow this  
Followers 0