Jump to content

StdOutRead(), I'm doing something wrong..


Recommended Posts

Hi Guys,

I made a small tool that will run a SQL Agent job.

It basically executes a command. I'm trying to retrieve the output so the user can know if it was successful. I keep getting a blank.

#include 
#include 
#include 
#include 
#include 
#include 

#region ### START Koda GUI section ### Form=C:\Users\tspitz\Dropbox\Coding\SQLJobRunner\Form1.kxf
$Form1 = GUICreate("SQLJob", 195, 147, 192, 124)
$Input1 = GUICtrlCreateInput("", 7, 24, 177, 21)
$Input2 = GUICtrlCreateInput("", 7, 70, 177, 21)
$Button1 = GUICtrlCreateButton("RUN", 17, 104, 161, 33)
$Label1 = GUICtrlCreateLabel("Server\Instance:", 7, 6, 84, 17)
$Label2 = GUICtrlCreateLabel("Job Name:", 7, 48, 55, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

$objSystemInfo = ObjCreate("ADSystemInfo")
$domain = $objSystemInfo.DomainShortName

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
If $domain <> "BROOKLYN" Then
$u = InputBox("User", "Please enter your username", "DOMAIN\USER or SA")
$p = InputBox("Password", "Please enter your password", "", "*")
$usr = "-U " & GUICtrlRead($u) & " "
$pass = "-P " & GUICtrlRead($p)
Else
$usr = ""
$pass = ""
EndIf
$feed = RunWait("sqlcmd " & $usr & $pass & " -S " & '"' & GUICtrlRead($Input1) & '"' & " -E -Q" & """" & "exec msdb.dbo.sp_start_job " & "'" & GUICtrlRead($Input2) & "'""", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$feed2 = StdoutRead($feed)
MsgBox(0, "", $feed2)
Exit
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Any ideas would be appreciated!

Link to comment
Share on other sites

tes5884,

I odn't know what "sqlcmd" is but I suspect that you need to run it from the command interpreter. You then loop on the results using stdoutread. The following is an example of this

; example of using stdout with network commands
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
Local $Gui010  = GUICreate("Network Properties", 800, 600)
Local $Button1 = GUICtrlCreateButton("IPCONFIG",10,  10, 75, 25)
Local $Button2 = GUICtrlCreateButton("NETSTAT", 90, 10, 75, 25)
Local $clear   = GUICtrlCreateButton("Clear Display", 700, 10, 90, 25)
     GUICtrlSetBkColor($clear,0xaaaaaa)
     GUICtrlSetFont($clear,10,800,default,'times new roman')
                 GUICtrlCreateLabel("PARM = ",175,15,50,25)
Local $parm    = GUICtrlCreateEdit('',225,10,75,25,$ss_sunken)
     GUICtrlSetFont($parm,12,800)
     GUICtrlSetState($parm,$gui_focus)
Local $dos    = GUICtrlCreatebutton('DOS CMD >',315,10,75,25)
     ;GUICtrlSetFont(-1,8.5,600)
Local $doscmd  = GUICtrlCreateEdit('',400,10,290,25,$ss_sunken)
     GUICtrlSetFont($doscmd,12,800)
Local $Edit010 = GUICtrlCreateEdit("", 10,40,780,550, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll + $es_readonly)
                 GUICtrlSetFont(-1,8.5,800,default,'courier new')
GUISetState(@SW_SHOW)
net_properties()
Func net_properties()
 Local $rslt,$out
 While 1
   $msg = GUIGetMsg()
   Select
    Case $msg = $GUI_EVENT_CLOSE
     ExitLoop
    Case $msg = $Button1
     $rslt = Run(@ComSpec & " /c ipconfig " & GUICtrlRead($parm), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
     While 1
      $out = StdoutRead($rslt)
      If @error then exitloop
      GUICtrlSetData($edit010,$out & @lf,1)
     WEnd
    Case $msg = $Button2
     $rslt = Run(@ComSpec & " /c netstat " & GUICtrlRead($parm), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
     While 1
      $out = StdoutRead($rslt)
      If @error then exitloop
      GUICtrlSetData($edit010,$out & @lf,1)
     WEnd
    Case $msg = $dos
     $rslt = Run(@ComSpec & " /c " & GUICtrlRead($doscmd), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
     While 1
      $out = StdoutRead($rslt)
      If @error then exitloop
      GUICtrlSetData($edit010,$out & @lf,1)
     WEnd
    Case $msg = $clear
     GUICtrlSetData($edit010,"")
   EndSelect
 WEnd
EndFunc

Also, what's up with the blank includes????

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Any ideas would be appreciated!

RunWait() return the exit code, not PID. Replace with Run() and ProcessWaitClose() (use the PID) to get the same functionality.

Also, what's up with the blank includes????

kylomas

It's a forum bug, where have you been the last couple of months? ;):P
Link to comment
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
 Share

  • Recently Browsing   0 members

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