Re: WshShell.Exec output read impossible until command finished



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
.



Relevant Pages

  • Re: batch file to delete files based on criteria
    ... The Advanced Version of Snapshot will create date/time coded backups that ... This script is included with the FREE Advanced NT/2K/XP/K3 Command Library ... script will perform CONSISTENTLY under Windows NT4, 2000, XP and Server ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Swap/Remap Ctrl and Alt keys.......Finally
    ... startup/login script. ... It shows a message saying you need to add a line to a login script to ... The back quotes mean that the output of the "uname -n" command shall be ... options are much more comprehensive that those in Windows (does Windows ...
    (Ubuntu)
  • Re: Windows 2000 remote login problems
    ... Whenever a user forgets their Windows password we ... When the user forgets his password, he logs on with the user Setpassword. ... and the script asks for the user name to reset as well as the ... Changing password from a script (vbscript as well as command line): ...
    (microsoft.public.win2000.security)
  • WshShell.Exec output read impossible until command finished
    ... I've done a script to force remove of old DCs. ... I'm using NTDSUTIL command line tool for that, ... How can I have a live output read (like under Windows 2003 DC)? ...
    (microsoft.public.scripting.vbscript)
  • WshShell.Exec output read impossible until command finished
    ... I've done a script to force remove of old DCs. ... I'm using NTDSUTIL command line tool for that, ... How can I have a live output read (like under Windows 2003 DC)? ...
    (microsoft.public.windows.server.scripting)