Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WshShell.Run vs WshShell.Exec

16 views
Skip to first unread message

Brian Baker [MVP]

unread,
Feb 5, 2003, 9:38:42 PM2/5/03
to
I have a script (written in VBScript) that calls a command-line utility.
I had been doing this with WshShell.Exec, which has been working for
several months. However, within the last few days the utility has been
hanging right before it finishes.

I made some changes to the script so that this utility could be called
through WshShell.Run instead, which worked. Can anyone explain why that
would be? Also, I read some past messages in this newsgroup regarding
problems using WshShell.Exec with programs that generate a lot of text to
StdErr. Could this be the problem?

Thanks,
Brian Baker
--
Microsoft MVP -- ASP / ASP.NET
Please post responses to the group


Michael Harris (MVP)

unread,
Feb 6, 2003, 12:09:40 AM2/6/03
to
> .... Also, I read some past messages in this newsgroup

> regarding problems using WshShell.Exec with programs that generate a
> lot of text to StdErr. Could this be the problem?
>

It certainly could be and probably is...

Here's the WshShell.Exec template code I use to ensure that all output is
captured and the Exec'd process doesn't block on a full stdout buffer...

sCmd = "some command string"

set shell = createobject("wscript.shell")
Set d = CreateObject("Scripting.Dictionary")

set wsx = shell.exec(sCmd)
set wsxOut = wsx.stdout

do: wscript.sleep 10
do until wsxOut.atendofstream
d(d.count) = wsxOut.readline
loop
loop until wsx.status <> 0 and wsxOut.atendofstream

arLines = d.items()

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Windows 2000 Scripting Guide
Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp
Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp
Download details: System Administration Scripting Guide Scripts
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=B4CB2678-DAFB-4E30-B2DA-B8814FE2DA5A

Brian Baker [MVP]

unread,
Feb 6, 2003, 10:21:26 AM2/6/03
to
Michael Harris (MVP) wrote:
>> .... Also, I read some past messages in this newsgroup
>> regarding problems using WshShell.Exec with programs that generate a
>> lot of text to StdErr. Could this be the problem?
>
> It certainly could be and probably is...
>
> Here's the WshShell.Exec template code I use to ensure that all output
is
> captured and the Exec'd process doesn't block on a full stdout buffer...

Hmm, after thinking about it a little more I believe I know what the
problem is... Previously, I was just waiting until WshScriptExec.Status
<> 0, and then doing a .StdErr.ReadAll. I guess I need to be pulling it
out of the buffer as it goes so that the buffer does not get full. I
think that is what is happening... the program is waiting for the buffer
to be emptied so that it can add additional text to the buffer.

Do you know where to find documentation about the max size of the buffers?
I tried looking for some documentation about the NT 4 command shell but I
couldn't locate it on MSDN.

Michael Harris (MVP)

unread,
Feb 6, 2003, 8:55:36 PM2/6/03
to
> Do you know where to find documentation about the max size of the
> buffers? I tried looking for some documentation about the NT 4
> command shell but I couldn't locate it on MSDN.

You can search around on MSDN.

Character-Mode Applications
http://msdn.microsoft.com/library/en-us/dllproc/base/character_mode_applications.asp

is probably the best place to start.

Is there a reason you really need to know the max size? As long as you read
from the Exec'd process's StdOut as it executes, you shouldn't have a
problem.

0 new messages