WshShell.Run vs WshShell.Exec 
Author Message
 WshShell.Run vs WshShell.Exec

 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
{*filter*} 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



Mon, 25 Jul 2005 10:38:42 GMT  
 WshShell.Run vs WshShell.Exec

Quote:
> .... 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_overvie...
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&Family...



Mon, 25 Jul 2005 13:09:40 GMT  
 WshShell.Run vs WshShell.Exec

Quote:

>> .... 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.

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



Mon, 25 Jul 2005 23:21:26 GMT  
 WshShell.Run vs WshShell.Exec

Quote:
> 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_a...

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.

--
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_overvie...
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&Family...



Tue, 26 Jul 2005 09:55:36 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. runas with WshShell.Exec versus WshShell.Run

2. WshShell.run vs. Tasks

3. How to wait for termination of program started with WshShell.Exec

4. using WshShell.Exec

5. - WSHSHELL.EXEC error in ASP Web Page

6. WshShell.Exec Passing Invalid Argument to CL App

7. WshShell.Exec what is wrong?

8. WSH 5.6 WshShell.Exec - Minimized Window?

9. Basic WshShell.Exec problem

10. WshShell.Exec: reaping return codes and waiting for termination

11. q: asynch piping of WshShell.Exec.StdOut

12. WshShell.Exec without command prompt window?

 

 
Powered by phpBB® Forum Software