Jump to content
Sign in to follow this  

shell out and wait but capture the output

Recommended Posts

Hi I'm trying to restart a service using the psservice.exe command (let's call it myService)

I do this by executing a ShellExecuteWait command. The value returned is whether the command executes successfully (always) What I want though is the output coming back.

If the restart does not work I'll see "error restarting myService" in the shellbox.

How can I capture this output for processing in autoit?

Conversely, I tried to set parameter to pipe the output to a file to read after but I don't see the file getting generated.

Here's my code snippet

Func _RestartAmo($node)

;run psservice on the amoagent to restart

Dim $program, $cmd, $pipelog, $params

$program = "psservice.exe"

$cmd = "restart myService"

$pipelog = " > checkresult.log"

$params = "\\" & $node & " " & $cmd & $pipelog

Opt("RunErrorsFatal", 0)

Dim $val

$val = ShellExecuteWait($program,$params)

Opt("RunErrorsFatal", 1)

; script waits until psservice.exe closes

if _CheckAmoRestartLog() Then

return True


Return False



Func _CheckAmoRestartLog()

Dim $logfile


Dim $myArray

If Not _FileReadToArray($logfile,$myArray) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)



For $x = 1 to $myArray[0]

if StringRegExp( $myArray[1], "error starting myService") Then

FileDelete ( $logfile )

return False ; there was a problem restarting the agent



FileDelete ($logfile)

return True ; no errors found


Share this post

Link to post
Share on other sites

hmmm looks like I can do what I want with the servicecontrol.au3 module.

however I'd like to know what I'm doing wrong in my code and why it doesn't generate the pipe file.


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...