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


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



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish