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

Jerold Schulman

May 10, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today


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 oUserDNset 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



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like