Batch File that Output CLI Expression to Notepad.

Command Line Interface (CLI) tools often get the job done much faster than navigating through a GUI. CLI tools can also generate a lot of information. Some tools can generate more information than can be viewed in a CLI window. Here is a batch that will take the output of any CLI expression, command or tool, along with up to eight parameters and present it temporarily in Notepad.

@echo off
::Usage command [command parameters]
REM This script captures the output of any commandline utility
REM that writes the console and sends it to Notepad
REM if no command is specified, don’t do anythingREM and go to the end of the script.
if %1$==$ GoTo :EOF
REM Specify the temp file variable
set tmpFile=%temp%\~guifytmp.$$$
echo Calling %1 %2 %3 %4 %5 %6 %7 %8 %9
Call %1 %2 %3 %4 %5 %6 %7 %8 %9 > %tmpFile% && start notepad
%tmpFile% && del %tmpFile%
REM Clear the temp file variable
set tmpFile=

Put the batch file in your Windows directory or some directory in your path. To use the file, type this at a CLI prompt:

Guify SomeCommand

For example:

Guify ipconfig /displaydns

to show the DNS entries cached locally. The batch file redirects the command output to a temporary text file. Then it opens the text file in Notepad. Once Notepad is closed, the temp file is deleted. You can copy and paste the information in Notepad to another file or use SaveAs.

The tool works for most CLI commands but is not 100-percent foolproof. There are some commands and utilities that can’t be redirected. For example, something like “netstat /? > test.txt” will fail, which means “guify.bat” will also fail. But a command line “guify netstat -an” will work.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: