Jump to content
Sign in to follow this  
autoitxp

StdoutRead Question

Recommended Posts

autoitxp

Hello

im not really sure doing write way . let me know if there is other better way to to do it serviceex.exe is application which install non gui application as service . need code optimization :)

Func _ServiceInstall($ServiceExE = "serviceex.exe", $ServiceName = "_test", $ServiceParm = "install")
    Local $SvExPid = Run(@ComSpec & " /c " & $ServiceExE & " " & $ServiceParm & " " & $ServiceName, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    If $SvExPid Then ProcessWaitClose($SvExPid)
    Local $CmdLineRead = StdoutRead($SvExPid)
    Local $aArray = StringSplit(StringTrimRight(StringStripCR($CmdLineRead), StringLen(@LF)), @LF) ;_ArrayDisplay($aArray)
    If Not @error Then
        If $aArray[7] == "Install service succeeded." Or $aArray[6] == "Couldn't create service! Perhaps it is already installed." Then
            Return True
        EndIf
    EndIf
    Return False
EndFunc ;==>_ServiceInstall
Edited by autoitxp

Share this post


Link to post
Share on other sites
W4RD14L3R

Usually if you want to read from the STDOut stream it is usually wise to run it through a loop, there is no telling how long before it outputs data but sometimes can take a while.

Take a look at "SC" from the cmd.exe it has helped me alot when creating services for programs.

Usage:

SC Create "service name" binPath= "app_path" start= "auto"

Share this post


Link to post
Share on other sites
water

You don't have to read the STDOUT stream in a loop. There was a post a few weeks ago that you could run a program and read the STDOUT stream in one go.

If I find the thread I will post the link.

Edit:

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×