bengmau Posted March 19, 2008 Share Posted March 19, 2008 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 Else Return False EndIf EndFunc Func _CheckAmoRestartLog() Dim $logfile $logfile="checkresult.log" Dim $myArray If Not _FileReadToArray($logfile,$myArray) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf 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 EndIf Next FileDelete ($logfile) return True ; no errors found EndFunc Link to comment Share on other sites More sharing options...
bengmau Posted March 19, 2008 Author Share Posted March 19, 2008 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. Thanks 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