Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Neverending exec process

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
Simple code...
Code:
Set wshShell = WScript.CreateObject("WScript.Shell")
dirCmd = "cmd /c dir /s /b /O-D buildlog.htm"

Set X = wshShell.Exec(dirCmd)
Do While X.Status = 0
  MsgBox "Looping..." & X.Status
  WScript.Sleep 1000
Loop
MsgBox "Out of loop"

Works great usually, but when the number of matches gets too big (I think around 30-40, not certain though), the process never ends and my program goes into an infinite loop. (MsgBox's only there for debugging purposes).

Anyone have an idea or a workaround?
 
Workaround... remove the cmd /c

So, there's the fix... now, can anyone explain to me why this fixes it?
 
Hello skiflyer,

This is a known "bug" if I may say so. It seems to be delinquant endofstream of the stdout making comspec instance not ending waiting eternally to end.

Generally, do not allow cmd /k or cmd /c or command /k or command /c. For instance:
.exec("ping xxx...")
and
.exec "cmd /k ping xxx..." ' to _avoid_ --- hang

regards - tsuji
 
Well, removing the cmd /c worked great on my development machines, but on my production machines I get an error that the file cannot be found.

The file in question being 'dir'

So... still stuck afterall, but a new stuck, anyone know?
 
IMHO, cmd /c is MANDATORY for all internal commands (DIR, SET, ...)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok... then do you have any advice on making it work?

In my case using cmd /c causes a freeze.
 
skiflyer,

The solution is that you use in these particular case:
wshshell.run dirCmd

regards - tsuji
 
But I thought run returns an error code rather than the output of the command... I'll tinker more with run I guess
 
So, the only thing crossing my mind is to use wscript.run to dump the results to a file
Code:
cmd /c dir /s /b /O-D build.html >> temp.txt

And then read in the contents of that file... but now this is getting to a ridiculous level of complexity.

Before I go down that road, does anyone have another suggestion?
 
skiflyer,

Complexity is only apparent sometimes. One should not expect having programming paradise where there is always only one-liner to call up a built-in service responding to everybody's any need. Even then, you have a manual of a unmangeable complexity.

- tsuji
 
I agree with the concept, but I've yet to find a language where I can't read an output stream directly.

It's an especially large shortcoming with a scripting language where streams and pipes and redirects are used extensively.
 
Hi! -
I hope skiflyer and tsuji are stil monitoring this thread, but I would appreciate insights from anyone else interested in this problem...

I have the same problem, but I am NOT using cmd. I have virtually identical scripts running an FTP session. One has a large amount of output the other doesn't. The one with a large amount of output hangs, the one with little output doesn't.

I try to hide the FTP from the user and here is code that works in both cases, but I cannot (at least I haven't been able to figure how to) do some rudimentary error checking.
Code:
 Set Script=WScript.CreateObject("WScript.Shell")
 Script.Run "ftp -n -s:" & sfName & " 99.99.99.99", 0, True
 scriptfile.Delete True
 set scriptfile = nothing
 set oFSo = nothing

Running it THIS way, I can do some error checking, but the box isn't hidden, which I can live with. THIS is the code that hangs when there is too much data written to stdout

Code:
 Set Script=WScript.CreateObject("WScript.Shell")
 set X = Script.Exec("ftp -n -s:" & sfName & " 99.99.99.99")
 Do while X.Status = 0
    WScript.sleep 250
 Loop
 scriptfile.Delete True
 set scriptfile = nothing
 set oFSo = nothing

*** Look for FTP Errrors
 While Not X.StdOut.AtEndOfStream
  sLine = Trim(X.StdOut.ReadLine)
  IF LEft(sLine,10) = "Cmd Failed" or Left(sLine,12) = "Login Failed" or Left(sLine,17) = "No Such Directory" or Right(sline,14) = "File not found"  THen
      MSgBOx "FTP Down Failed with message: " & sLine
      Wscript.quit
  End IF
 Wend

Thnask for any help
TLogan
The man without an interesting moniker
 
Hopefully someone else can come in with more complete information... but here's as much as I can offer this morning before the meetings start.

Personally, I've had nothing but trouble with the Exec method... I would stick with the run. And then, I believe, FTP will set a system variable (ERROR_LEVEL I Think) with the error value... so you can use that to check for errors.

I could be wrong, I'm on the VBS guy around here, but that's what the desk next to me is saying anyway.
 
Hello tlogan,

In your sfname, try put quit as the last line of instruction. Do you still have it pending?

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top