WshShell.Exec what is wrong? 
Author Message
 WshShell.Exec what is wrong?

I'm building an automated build system using JScript and have run into
a bit of a problem.  The output from my build.cmd is a 300 - 400 lines
and using WshShell.Exec stops after about 230 lines.  I use the
technique below in several other locations with no problems but when
the output is large it always fails.  Im on XP using version 5.6.

var shell = new ActiveXObject("WScript.Shell");
var wsx = shell.Exec("%comspec% /c build.cmd");
while((wsx.Status == 0) && (!wsx.StdOut.AtEndOfStream)){
  WScript.Sleep(10);
  while(!wsx.StdOut.AtEndOfStream) {
     WScript.Echo(wsx.StdOut.ReadLine());
  }

Quote:
}

I tried ReadAll() but that doesn't produce any output.

TIA,
David
---



Mon, 17 Oct 2005 06:50:22 GMT  
 WshShell.Exec what is wrong?
am 01.05.03 00:50 sprach David Ferraro dieses:

Hi David,

Quote:
> I'm building an automated build system using JScript and have run into
> a bit of a problem.  The output from my build.cmd is a 300 - 400 lines
> and using WshShell.Exec stops after about 230 lines.  I use the
> technique below in several other locations with no problems but when
> the output is large it always fails.  Im on XP using version 5.6.

> var shell = new ActiveXObject("WScript.Shell");
> var wsx = shell.Exec("%comspec% /c build.cmd");

Just drop these two lines:

-- >> while((wsx.Status == 0) && (!wsx.StdOut.AtEndOfStream)){
-- >>   WScript.Sleep(10);

Quote:
>   while(!wsx.StdOut.AtEndOfStream) {
>      WScript.Echo(wsx.StdOut.ReadLine());
>   }

-- >> }

change it to:

var shell = new ActiveXObject("WScript.Shell");
var wsx = shell.Exec("%comspec% /c build.cmd");
while(!wsx.StdOut.AtEndOfStream) {
   WScript.Echo(wsx.StdOut.ReadLine());

Quote:
}

afaik you don't have to check the status-flag here,
because you can access/read the StdOut-TextStream
whether the Exec-Object is terminated or not.
Moreover you dont need to check EOF twice and
you don't need to use "Wscript.Sleep" here, because
"ReadLine" has an implicit Wait-Option.
It waits until it reads an End-Of-Line-Sequence.
If there is none, it'll wait forever.

HTH,
Christoph

Quote:
> I tried ReadAll() but that doesn't produce any output.



Mon, 17 Oct 2005 19:11:13 GMT  
 WshShell.Exec what is wrong?
Thanks for the quick reply.  I made the changes you recommended and
still have a problem.  To make sure everything was working correctly I
created a txt file with text on 1000 lines and used type test.txt as
the command.  That works fine.  It seems the problem is with the
commands I'm calling.  The first is:
 cvs update -P -d
After trying several things this works:

var shell = new ActiveXObject("WScript.Shell");
var wsx = shell.Exec("%comspec% /c cvs update -P -d");
while (!wsx.StdOut.AtEndOfStream) {
   WScript.Echo("O " + wsx.StdOut.ReadLine());
   while (!wsx.StdErr.AtEndOfStream) {
      WScript.Echo("E " +wsx.StdErr.ReadLine());
   }

Quote:
}

It seems most but not all of the output is sent to StdErr.  Other
Suggestions?

The other Exec runs build.cmd which has some dos commands and runs
wzzip a few times.  Wzzip is a command line tool that zips up some
files.  It stops in the middle of the last wzzip call.  This was fixed
by removing a cd (change directory)call a couple of lines earlier and
adding path info to the wzzip params.  Any ideas as to why I had to
make these changes?

Thanks,
David

Quote:

> am 01.05.03 00:50 sprach David Ferraro dieses:

> Hi David,

> > I'm building an automated build system using JScript and have run into
> > a bit of a problem.  The output from my build.cmd is a 300 - 400 lines
> > and using WshShell.Exec stops after about 230 lines.  I use the
> > technique below in several other locations with no problems but when
> > the output is large it always fails.  Im on XP using version 5.6.

> > var shell = new ActiveXObject("WScript.Shell");
> > var wsx = shell.Exec("%comspec% /c build.cmd");

> Just drop these two lines:

> -- >> while((wsx.Status == 0) && (!wsx.StdOut.AtEndOfStream)){
> -- >>   WScript.Sleep(10);

> >   while(!wsx.StdOut.AtEndOfStream) {
> >      WScript.Echo(wsx.StdOut.ReadLine());
> >   }
> -- >> }

> change it to:

> var shell = new ActiveXObject("WScript.Shell");
> var wsx = shell.Exec("%comspec% /c build.cmd");
> while(!wsx.StdOut.AtEndOfStream) {
>    WScript.Echo(wsx.StdOut.ReadLine());
> }

> afaik you don't have to check the status-flag here,
> because you can access/read the StdOut-TextStream
> whether the Exec-Object is terminated or not.
> Moreover you dont need to check EOF twice and
> you don't need to use "Wscript.Sleep" here, because
> "ReadLine" has an implicit Wait-Option.
> It waits until it reads an End-Of-Line-Sequence.
> If there is none, it'll wait forever.

> HTH,
> Christoph

> > I tried ReadAll() but that doesn't produce any output.



Tue, 18 Oct 2005 01:50:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. WshShell.Run vs WshShell.Exec

2. runas with WshShell.Exec versus WshShell.Run

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. WSH 5.6 WshShell.Exec - Minimized Window?

8. Basic WshShell.Exec problem

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

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

11. WshShell.Exec without command prompt window?

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

 

 
Powered by phpBB® Forum Software