Re: WshShell.Exec output read impossible until command finished
- From: T Lavedas <tglbatch@xxxxxxx>
- Date: Mon, 22 Jun 2009 14:01:36 -0700 (PDT)
On Jun 21, 10:51 am, V Poirot <vpoi...@xxxxxxx> wrote:
Hi
I've done a script to force remove of old DCs.
I'm using NTDSUTIL command line tool for that, and it's working like I
want, except under Windows 2008 (DC)!
I'm unable to read output until command (ntdsutil) has exited. But it's not
what I want, because other inputs depends on previous output.
Question: How can I have a live output read (like under Windows 2003 DC)?
or is their another way to force DC removal (by scripting)?
Here is a sample of my script:
Set WshShell = CreateObject("WScript.Shell")
strCmd = "cmd /c ntdsutil ""popups off"" ""me c"" co ""co to se %
computername%"" q ""se op ta"" ""list sites"""
Set oExec = WshShell.Exec(strCmd)
tmpline = ""
While Not oExec.StdOut.AtEndOfStream
tmpline = LCase(oExec.StdOut.ReadLine)
....
....
' some output analyse...
' and sometimes, I've to send new command, like this one:
oExec.stdIn.WriteLine "select site " & siteSelection
....
....
WEnd
Thanks for your help
Vincent
[FR]
Here is a little test script that shows one way to unblock the output
of the Exec process ...
set con = wsh.stdout ' use this to show intermediate output
sCmd = "%comspec% /c dir *.txt /o" ' put your command here
with createobject("wscript.shell").Exec(sCmd)
set Out = .StdOut
set SErr = .StdErr
set Input = .StdIn
Do While Not .Status = 1 or _
Not SErr.AtEndofStream or _
Not Out.AtEndofStream
wsh.Sleep 10
if not SErr.AtEndofStream then
e = ""
do until Instr(s, vbLF) or SErr.AtEndofStream
e = e & SErr.read(1)
loop
con.write e & vbnewline ' just to prove processing
end if
if not Out.AtEndofStream then
s = ""
do until Instr(s, vbLF) or Out.AtEndofStream
s = s & Out.read(1)
loop
con.write s & vbnewline ' just to prove processing
end if
Loop
end with
wsh.echo "Done"
Note that the test in the Do loops can be changed to match the output
you're interested in catching (or add it between the lines).
This approach, as written, only works when executed with the
cscript.exe host in a command console window. It may be possible to
rewrite the console output part to send the output to an IE window
instead, so that the console part can be separated from the display
part, but I haven't tried that yet.
Tom Lavedas
.
- Follow-Ups:
- Re: WshShell.Exec output read impossible until command finished
- From: T Lavedas
- Re: WshShell.Exec output read impossible until command finished
- References:
- WshShell.Exec output read impossible until command finished
- From: V Poirot
- WshShell.Exec output read impossible until command finished
- Prev by Date: Re: Clean out old files from multiple subfolders
- Next by Date: Re: Clean out old files from multiple subfolders
- Previous by thread: WshShell.Exec output read impossible until command finished
- Next by thread: Re: WshShell.Exec output read impossible until command finished
- Index(es):
Relevant Pages
|