Subscribe to Windows IT Pro
May 11, 2006 12:00 AM

JSI Tip 10482. How can I pipe or redirect the output of an executable when run from a Vbscript?

Windows IT Pro
InstantDoc ID #85855
Rating: (0)


Redirecting STDOUT to STDIN (piping) is supported by CMD.EXE, not Vbscript (WSH).

To pipe the output of an executable to the input of another process in Vbscript simply involves using CMD.EXE to run them.

The location of CMD.EXE is defined by the %comspec% environment variable.

Example

If you wanted to run dsquery user -samid %username% -o dn | dsget user -memberof from a Vbscript, use:
Dim oUserDN
set oShell = createobject("wscript.shell")
mystr = "dsquery user -samid %username% -o dn | dsget user -memberof"
set oUserDN = oShell.exec("%ComSpec% /c 
& mystr &
") Wscript.Echo oUserDN.StdOut.readall



Related Content:

ARTICLE TOOLS

Comments
  • babitha thomas
    1 month ago
    Apr 24, 2012

    There is a mistake in your command...

    mystr = "dsquery user -samid %username% -o dn | dsget user -memberof"
    set oUserDN = oShell.exec("%ComSpec% /c & mystr & ")

    cmd.exe will take the Quotes of mystr..hence u will not get any output..

    in my program i did as below

    set objExec= WshShell.exec("%ComSpec% /c dsquery group -name " & HostName & " | dsget group -members -expand")

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.