yug2wa
Last Updated: February 25, 2016
·
100
· extofer

Working with results on Windows command-line interfaces

When working on MS Windows, command-line interfaces may get cumbersome if you want to work with results from the CLI. Several methods to work with results from the CLI are to understand redirects and pipes. Whether you are on PowerShell, MS-DOS or GitBash on Windows, these command tips should work.

Redirect

> will redirect the output of the commend to a file you provide

:: DOS
dir /q > c:\OutPutFile.txt

Append

Redirecting will always create a new file overwriting previous output. >> will append the results to an existing file

#PowerShell
get-date >> c:\OutPutFile.txt

Putting it all together

Now you can use a pipe | to work with the output. The pipe redirects the output to a subsequent command. For instance, after you appended the get-date to the original directory information in the OutPutFile.txt, you can redirect to a text editor

#PowerShell
get-date >> c:\OutPutFile.txt | notepad c:\OutPutFile.txt

This will allow to work with the output in a text file by redirecting the results and sending them to a text editor for additional use. Additionally, if you want to copy and paste the output, you can pipe the output to the clipboard

#using GitBash
git status | clip

Knowing these tips have helped me from time to time and I hope it can help you.