DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Run Command On String, Returning Output

09.02.2005
| 6573 views |
  • submit to reddit
        This is basically implementing a Unix-style filter in Windows Scripting Host.

var shell = WScript.CreateObject("WScript.Shell");

var exec = shell.Exec("tr a-z A-Z");
exec.StdIn.Write("hello, world");
exec.StdIn.Close();
WScript.StdOut.Write(exec.StdOut.ReadAll());

Watch out for deadlocks if you're writing huge amounts of data into the command, but it works for reasonable amounts of data (the buffer is probably something like 4K, but I've not tested...)