Cmd.Exe and Which

I love bash.

I hate cmd.exe. This is mostly due to unfamiliarity, but I don’t care, I hate regardless.

Enter, me configuring cc.net and msbuild complaining about a version 10, Visual Studio 2008, sln file. This is because the msbuild that cc.net knows about is the 2005 msbuild. So I fire up a 2008 Command Prompt run msbuild, and everything runs fine.

Now it seems like the “Microsoft way” would be for me to examining the path manually, go trouncing through the directories in this path, looking for msbuild. WTF??? I don’t work that way.

In Linux, there is a command called which, which will tell you which command you are executing if you type it at the prompt. All it does is search your path, in order, to tell you which command would run if you actually type a command. The exception is shell built-ins, but lets ignore that.

[jrwren@utonium:$] which ls
/bin/ls

It turns out this is TRIVIAL to write as a batch file. cmd.exe has the goods for you. I’m writing this here because MS keeps changing urls on me and my del.icio.us links don’t work anymore.

Maybe this link won’t change.

which.bat:

echo %~$PATH:1

Pretty slick eh?

IMNSHO this should be in every windows directory on every windows computer everywhere 🙂 Its 2008. I’ve been living with which in linux/unix since I started using it in 1995. Please step into 13 years ago by copying this batch file to all of your windows computers.

3 thoughts on “Cmd.Exe and Which”

  1. Nice, thank you!

    I’ve long thought that so many of *nix’s standbys would be very easy to implement under cmd.exe or anywhere else, so why hasn’t MS done so?
    It seems like pure not-invented-here snottiness.

    (Cygwin, of course, is the ultimate solution, but why should it be necessary?)

  2. Yes, MS is pretty confused when it comes to cmd.exe and what it wants to allow with .bat and .cmd files.

    Case in point, look at the vcvars group of .bat files which comes with Visual Studio. They are buggy and actually don’t work! under certain cases.

    between cmd, wsh, and PowerShell there is no clear path. I guess powershell is the clear path, but it isn’t installed on all windows, so WSH is today’s Lowest Common Denominator.

    I’m not sure why to pick cmd over WSH except for maybe that WSH/Cscript doesn’t easily allow for calling other cmd/wsh programs. It is more like perl or python and calling execve.

    Oh well. I am just glad to have cygwin.

Comments are closed.