Jump to content

Recommended Posts

Posted

Hello, I'm attempting to create an application that will kill services and start them.

I am successfully able to get the output as long as the net command works.post-51279-12513496235713_thumb.jpg

I run that same command again to cause the net utility to error and now it writes it's output to the console of sciTE...?post-51279-12513496321306_thumb.jpg

I've tried including the error. When i do that i not only do not get a msgbox, i also see nothing in the sciTE console.

Obviously a workaround would be to query the service with the SC utility. I'm curious to why this is not working. I'm probably missing a step somewhere.

Well without further delay here's the code in all of its glory.

#include <Constants.au3>

Local $serviceCmd = Run(@ComSpec & " /c net start spooler", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
Local $line = ""
While ProcessExists($serviceCmd)
    $line = ""
    $line = StdoutRead($serviceCmd)
    if StringInStr($line,"Service",2) > 0 Then
        MsgBox(0,"",$line)
        ExitLoop
    EndIf

Wend
Posted

The successful result text is read from STDOUT, but the errors must be read from STDERR.

One option would be to add $STDERR_CHILD to the STD I/O parameter of your Run call, then use StderrRead. (See the Example in the Help file)

Another option would be to redirect STDERR to STDOUT, like this:

Local $serviceCmd = Run(@ComSpec & " /c net start spooler 2>&1", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
No other code changes would be needed because you're already reading STDOUT.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...