The Beauty of Command-line Utilities

I like the way command-line tools can be adapted for automating complex tasks.

For instance, if you had to populate the list of names of computers in your LAN in a combo box, the net.exe command can be utilized with the Process.Start() method in C#

Process netsend = new Process();
netsend.StartInfo.FileName = "net.exe";
netsend.StartInfo.CreateNoWindow = true;
netsend.StartInfo.Arguments = "view";
netsend.StartInfo.RedirectStandardOutput = true;
netsend.StartInfo.UseShellExecute = false;
netsend.StartInfo.RedirectStandardError = true;
netsend.Start();

StreamReader sr = new StreamReader(netsend.StandardOutput.BaseStream, netsend.StandardOutput.CurrentEncoding);

string sss = "";
while ((sss = sr.ReadLine()) != null)
{
if (sss.StartsWith("\\"))
comboBox1.Items.Add(sss.Substring(2).Substring(0, sss.Substring(2).IndexOf(" ")).ToUpper();
}

sr.Close();

Setting the CreateNoWindow property to true hides the console window.

Here is a list of command-line tools that I've found helpful (work in progress) -
Dear Reader, what are your favorite command-line tools?

Comments