From: Gil on
Is there a way to capture the contents of STDOUT if a command that is
issued via the EXEC method does not return?

Reason being is that I am executing a utility and sometimes it returns
enough information for me to process but the command never returns.

I have tried various things w/o success:
Bumping up the wait interval to several seconds but the command still
never returns.
Reading the STDOUT to a variable using the READALL method but that
didn't work.
Executing the command using the RUN method to a file but that also
hangs.
Issuing a Terminate but that aborts the script.

This is what I currently have to get around the hangups. Note
objShowReportLoops is reset further up in the script. This works for
most of the commands I issue except for some that I'm guessing
generate a lot of data or perhaps timeout because of system activity.
I'm not sure why the command never returns.

ShowReportsCmd = "cmd.exe /c vadmin command=ShowReport report=" &
RptName
set objShowReport = WshShell.Exec(ShowReportsCmd)
'Do Until objShowReport.Status = 1
Do Until objShowReportLoops > 0
Wscript.Sleep 1000
If objShowReport.Status = 1 Then
Exit Do
Else
Wscript.Echo "Cancelling ShowReport display because command did not
return results!"
set objShowReport = Nothing
set objShowReport = WshShell.Exec("cmd.exe /c echo Not Found.")
'objShowReport.Terminate
objShowReportLoops = objShowReportLoops + 1
Exit Do
End If
Loop

Any suggestions on how I can get around this?
From: Pegasus [MVP] on


"Gil" <gilbertcardenas(a)grocerybiz.com> wrote in message
news:745ad459-9213-453a-a2b4-1995e3fc6e8c(a)t20g2000yqa.googlegroups.com...
> Is there a way to capture the contents of STDOUT if a command that is
> issued via the EXEC method does not return?
>
> Reason being is that I am executing a utility and sometimes it returns
> enough information for me to process but the command never returns.
>
> I have tried various things w/o success:
> Bumping up the wait interval to several seconds but the command still
> never returns.
> Reading the STDOUT to a variable using the READALL method but that
> didn't work.
> Executing the command using the RUN method to a file but that also
> hangs.
> Issuing a Terminate but that aborts the script.
>
> This is what I currently have to get around the hangups. Note
> objShowReportLoops is reset further up in the script. This works for
> most of the commands I issue except for some that I'm guessing
> generate a lot of data or perhaps timeout because of system activity.
> I'm not sure why the command never returns.
>
> ShowReportsCmd = "cmd.exe /c vadmin command=ShowReport report=" &
> RptName
> set objShowReport = WshShell.Exec(ShowReportsCmd)
> 'Do Until objShowReport.Status = 1
> Do Until objShowReportLoops > 0
> Wscript.Sleep 1000
> If objShowReport.Status = 1 Then
> Exit Do
> Else
> Wscript.Echo "Cancelling ShowReport display because command did not
> return results!"
> set objShowReport = Nothing
> set objShowReport = WshShell.Exec("cmd.exe /c echo Not Found.")
> 'objShowReport.Terminate
> objShowReportLoops = objShowReportLoops + 1
> Exit Do
> End If
> Loop
>
> Any suggestions on how I can get around this?

There might be a very simple reason why the command appears to hang. In the
line

cmd.exe /c vadmin

you do not specifiy a drive, folder or extension for the vadmin command.
Where does vadmin reside? How does the script know where to find it? Is
vadmin perhaps a batchfile called vadmin.bat that is meant to invoke
vadmin.exe (again without drive or path) but invokes vadmin.bat instead? If
so then it will run in circles forever.

If you want your scripts to be robust then you must fully specify your file
names. Assuming that they are in the current location frequently causes
problems.

From: Gil on
On Aug 19, 10:52 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote:
> "Gil" <gilbertcarde...(a)grocerybiz.com> wrote in message
>
> news:745ad459-9213-453a-a2b4-1995e3fc6e8c(a)t20g2000yqa.googlegroups.com...
>
>
>
>
>
> > Is there a way to capture the contents of STDOUT if a command that is
> > issued via the EXEC method does not return?
>
> > Reason being is that I am executing a utility and sometimes it returns
> > enough information for me to process but the command never returns.
>
> > I have tried various things w/o success:
> > Bumping up the wait interval to several seconds but the command still
> > never returns.
> > Reading the STDOUT to a variable using the READALL method but that
> > didn't work.
> > Executing the command using the RUN method to a file but that also
> > hangs.
> > Issuing a Terminate but that aborts the script.
>
> > This is what I currently have to get around the hangups. Note
> > objShowReportLoops is reset further up in the script.  This works for
> > most of the commands I issue except for some that I'm guessing
> > generate a lot of data or perhaps timeout because of system activity.
> > I'm not sure why the command never returns.
>
> > ShowReportsCmd = "cmd.exe /c vadmin command=ShowReport report=" &
> > RptName
> > set objShowReport = WshShell.Exec(ShowReportsCmd)
> > 'Do Until objShowReport.Status = 1
> > Do Until objShowReportLoops > 0
> > Wscript.Sleep 1000
> > If objShowReport.Status = 1 Then
> > Exit Do
> > Else
> > Wscript.Echo "Cancelling ShowReport display because command did not
> > return results!"
> > set objShowReport = Nothing
> > set objShowReport = WshShell.Exec("cmd.exe /c echo Not Found.")
> > 'objShowReport.Terminate
> > objShowReportLoops = objShowReportLoops + 1
> > Exit Do
> > End If
> > Loop
>
> > Any suggestions on how I can get around this?
>
> There might be a very simple reason why the command appears to hang. In the
> line
>
> cmd.exe /c vadmin
>
> you do not specifiy a drive, folder or extension for the vadmin command.
> Where does vadmin reside? How does the script know where to find it? Is
> vadmin perhaps a batchfile called vadmin.bat that is meant to invoke
> vadmin.exe (again without drive or path) but invokes vadmin.bat instead? If
> so then it will run in circles forever.
>
> If you want your scripts to be robust then you must fully specify your file
> names. Assuming that they are in the current location frequently causes
> problems.- Hide quoted text -
>
> - Show quoted text -

Sorry, you're correct about fully specifying file names. The server
where the command was executing had the program set in the path
environment but I did fully qualify it on the script however it is
still hanging.
Although the original problem is that the command hangs, since I have
not been able to get around that I was trying to find a way to capture
the STDOUT contents before I destroyed the object so I could still use
what was in there as I am only interested in the first few lines
anyway.

Thanks for the response.
From: ekkehard.horner on
Gil schrieb:
> Is there a way to capture the contents of STDOUT if a command that is
> issued via the EXEC method does not return?
>
> Reason being is that I am executing a utility and sometimes it returns
> enough information for me to process but the command never returns.
[...]
Perhaps the Cow.vbs:

'' the cow

Option Explicit

WScript.Quit waitForCow()

Function waitForCow()
waitForCow = 1
Dim nCnt
For nCnt = 1 To 5
WScript.Echo "Muh", nCnt
WScript.Sleep 1000
Next
WScript.Echo "Done - but I won't come home."
MsgBox "muh"
WScript.Echo "Bye."
waitForCow = 0
End Function

and the Cowboy.vbs:

'' wait for the cow

Option Explicit

Const WshRunning = 0 ' The job is still running.
Const WshFinished = 1 ' The job has completed.

WScript.Quit waitForCow()

Function waitForCow()
waitForCow = 1
Dim sCmd : sCmd = "cscript Cow.vbs"
Dim oExc : Set oExc = CreateObject( "WScript.Shell" ).Exec( sCmd )
Do
WScript.Sleep 100
Select Case True
Case WshFinished = oExc.Status
WScript.Echo "WshFinished"
Exit Do
Case Else
Dim sLine : sLine = oExc.Stdout.ReadLine()
WScript.Echo sLine
If "Done" = Left( sLine, 4 ) Then
If WScript.Arguments.Named.Exists( "b" ) Then
MsgBox "Let's shoot the cow."
oExc.Terminate
End If
End If
End Select
Loop
WScript.Echo "Yipee"
waitForCow = 0
End Function

can help you.
From: Gil on
On Aug 19, 2:52 pm, "ekkehard.horner" <ekkehard.hor...(a)arcor.de>
wrote:
> Gil schrieb:> Is there a way to capture the contents of STDOUT if a command that is
> > issued via the EXEC method does not return?
>
> > Reason being is that I am executing a utility and sometimes it returns
> > enough information for me to process but the command never returns.
>
> [...]
> Perhaps the Cow.vbs:
>
>      '' the cow
>
>      Option Explicit
>
>      WScript.Quit waitForCow()
>
>      Function waitForCow()
>        waitForCow = 1
>        Dim nCnt
>        For nCnt = 1 To 5
>            WScript.Echo "Muh", nCnt
>            WScript.Sleep 1000
>        Next
>        WScript.Echo "Done - but I won't come home."
>        MsgBox "muh"
>        WScript.Echo "Bye."
>        waitForCow = 0
>      End Function
>
> and the Cowboy.vbs:
>
>      '' wait for the cow
>
>      Option Explicit
>
>      Const WshRunning  = 0 ' The job is still running.
>      Const WshFinished = 1 ' The job has completed.
>
>      WScript.Quit waitForCow()
>
>      Function waitForCow()
>        waitForCow = 1
>        Dim sCmd : sCmd     = "cscript Cow.vbs"
>        Dim oExc : Set oExc = CreateObject( "WScript.Shell" ).Exec( sCmd )
>        Do
>           WScript.Sleep 100
>           Select Case True
>              Case WshFinished = oExc.Status
>                WScript.Echo "WshFinished"
>                Exit Do
>              Case Else
>                Dim sLine : sLine = oExc.Stdout.ReadLine()
>                WScript.Echo sLine
>                If "Done" = Left( sLine, 4 ) Then
>                   If WScript.Arguments.Named.Exists( "b" ) Then
>                      MsgBox "Let's shoot the cow."
>                      oExc.Terminate
>                   End If
>                End If
>           End Select
>        Loop
>        WScript.Echo "Yipee"
>        waitForCow = 0
>      End Function
>
> can help you.

At a quick look I kind of understand the flow. I'll try to
incorporate that method into my script and post the results later.
Thanks for the tip,