You are here

How to: GNUWin32 tools in Command Prompt Portable

1 post / 0 new
BungieCord
Offline
Last seen: 5 years 2 weeks ago
Joined: 2009-03-12 16:11
How to: GNUWin32 tools in Command Prompt Portable

I've done a lot of modifying of environmental parameters for other PortableApps, usually involving editing the portable app's ".ini" file and inserting a batch file into the start-up process. But this one was much easier because Command Prompt Portable comes ready-made with it's own configuration file.

The standard *NIX command line tools are much more comprehensive than those provided with Windoze. If you're a UNIX or Linux geek, you probably already have discovered the GNUWin32 versions, which are Win32 ports of those wonderful *NIX tools.

I did this because I prefer to have my pet tools and diagnostics available when I troubleshoot a PC for friends or family (which happens more often than I care to admit) so I run as many of them as I'm able from my thumb drive. I can't live without several of those *NIX tools, like 'awk' and 'sed' and 'grep', so I decided to try to install their GNUWin32 versions to my thumb drive and run them in Command Prompt Portable. And because CPP includes its own configuration file, it couldn't be much easier.

The first step is to install the GNUWin32 utilities you will want to use on your own PC. You can get the packages you want to run, free, at:
http://gnuwin32.sourceforge.net/packages.html

When you download and install them, by default, they install to the C:\Program Files\GnuWin32 directory. When you're done, copy the entire GnuWin32 directory to the root of your thumb drive. Yup, that's right. They don't care that they're not being run on the PC they were installed to.

Now look in the directory on your portable drive:
\PortableApps\CommandPromptPortable\Data\Batch
and edit the file named 'commandprompt.bat'. What follows between the dashed lines is the contents of my commandprompt.bat:

----------------------------------------------------------------
@ECHO off

REM Don't let the variables I set in this batch file
REM affect those of the Host PC
SETLOCAL EnableExtensions

REM Set this shell's letter designation for this drive to match the host PC's
FOR /F "Tokens=1 delims=\" %%D In ('CD') Do Set CD=%%D\

REM Store all temp files on this portable drive
SET TEMP=%CD%Temp
SET TMP=%CD%Temp

REM Test for the existence of the GNUWin32 binary directory in this shell's path.
REM If it does not exist, append it to this shell's path.
REM If it does exist but is not the directory on this portable drive,
REM insert it at the beginning of the path.
path | find "GnuWin32\bin" & if ERRORLEVEL==1 (
set Path=%Path%;%CD%GnuWin32\bin
GoTo skip
)

path | find "%CD%GnuWin32\bin" & if ERRORLEVEL==1 set Path=%CD%GnuWin32\bin;%Path%

:skip

color 07
prompt $p$g

REM This will make the window identifiable as having the GNUWin tools
title Command Prompt Portable w/GNUWin32 tools

cls
ver
cd\
----------------------------------------------------------------

Feel free to delete the remarks lines. I included them to aid anyone trying to follow my logic.

Edit and save the file. If all went according to plan, you should now be able to start CPP and see "Command Prompt Portable w/GNUWin32 tools" at the top of the window. And you can confirm the shell can find your GNUWin32 tools by typing in one of the commands followed by "--h", like this:

http://img59.imageshack.us/img59/8034/gnuwin.jpg

Now you can run whatever *NIX command line tools you favor on any PC that will run PortableApps.