card page 6 - Dave's Blog

Search
My timeline on Mastodon

Which which - Batch File Hackiness

2007 Aug 9, 5:41To satisfy my hands which have already learned to type *nix commands I like to install Win32 versions of common GNU utilities. Unfortunately, the which command is a rather literal port and requires you to enter the entire name of the command for which you're looking. That is 'which which' won't find itself but 'which which.exe' will. This makes this almost useless for me so I thought to write my own as a batch file. I had learned about a few goodies available in cmd.exe that I thought would make this an easy task. It turned out to be more difficult than I thought.

for /F "usebackq tokens=*" %%a in ( `"echo %PATH:;=& echo %"` ) do (
    for /F "usebackq tokens=*" %%b in ( `"echo %PATHEXT:;=& echo %"` ) do (
        if exist "%%a"\%1%%b (
            for  %%c in ( "%%a"\%1%%b ) do (
                echo %%~fc
            )
        )
    )
)
The environment variables PATH and PATHEXT hold the list of paths to search through to find commands, and the extensions of files that should be run as commands respectively. The 'for /F "usebackq tokens=*" %%a in (...) do (...)' runs the 'do' portion with %%a sequentially taking on the value of every line in the 'in' portion. That's nice, but PATH and PATHEXT don't have their elements on different lines and I don't know of a way to escape a newline character to appear in a batch file. In order to get the PATH and PATHEXT's elements onto different lines I used the %ENV:a=b% syntax which replaces occurrences of a with b in the value of ENV. I replaced the ';' delimiter with the text '& echo ' which means %PATHEXT:;=& echo% evaluates to something like "echo .COM& echo .EXE& echo .BAT& ...". I have to put the whole expression in double quotes in order to escape the '&' for appearing in the batch file. The usebackq and the backwards quotes means that the backquoted string should be replaced with the output of the execution of its content. So in that fashion I'm able to get each element of the env. variable onto new lines. The rest is pretty straight forward.

Also, it supports wildcards:
C:\Users\davris>which.cmd *hi*
C:\Windows\System32\GRAPHICS.COM
C:\Windows\System32\SearchIndexer.exe
D:\bin\which.exe
D:\bin\which.cmd
PermalinkCommentswhich cmd technical batch for

Moved

2007 Aug 6, 4:07I've moved from my previous apartment in Redmond into Sarah's condo in Kirkland. Over the past week I'd been coming home from work and packing and sorting all of my belongings. Everything had a few destination options: I donated two carts of computer related junk (two CRTs, two desktops, six laptops, untold number of cables, piles of network and sound cards, etc) to RE-PC and six garbage bags of clothing that I either never wear or into which I have worn holes into friendly looking clothing donation bins. Of course I still need to find some place to get rid of my 15 inch CRT TV, VCR, DVD player, and X-Box. I finally emptied my bags of coins that had been collecting for about seven years (one of the bags was from my college orientation) through Coinstar and got ~$160. Some items seemed to fit very well at work like my satirical RIAA propaganda poster and my Darth Vader Nutcracker. This past weekend I had movers come and actually move my furniture. Most of its now in storage except for my living room which is moved into Sarah's second bedroom. Now all I have to do is unpack...PermalinkCommentsmove personal repc recycle nontechnical

MoHo Living

2007 May 13, 12:16My parents and grandmother came to visit the weekend before this current weekend, starting Friday May 4th. They arrived via their new motor-home which is quite the machine. Of course its my parents motor-home so its very well decorated inside including drapes and mini-chandelier. I didn't have a memory card for my camera at the time but I'm sure my parents will put up photos on their new blog dedicated to their motor-home at some point in the future.

At any rate, they parked the motor-home in an RV park in Issaquah so that Friday night I drove over to them and we ate at the conveniently closely located Pogachas. The next day they came over and I showed them the various cool looking things my computer connected to my flat screen TV can do. This includes Vista Media Center showing my photos from recent trips and Google Earth mapping out our respective homes and my recent trips (and Paris). Additionally, we played Wii which, unsurprisingly based on anecdotal evidence from varied sources across the Internet, was a seeming hit. Mom broke records playing bowling with my dad and I, Dad did an excellent job fishing, and Grandma's slow but steady win's the race approach to cow racing worked very well.

The next day I drove them to Seattle and we walked around Pike's Place. My parents made dinner that night at my place which was very good and made my apartment actually smell like cooked food. Also, we exchanged Christmas gifts. For the past two years I've flown back to my parents' house for Christmas and ended up with gifts I couldn't take with me in both directions. Those I left at their house they drove up and I was able to give them the ones I left at my place. They started the drive back the next day. I really enjoyed seeing them here.PermalinkCommentsmotorhome family personal nontechnical

Commenting Wishlist

2007 May 1, 4:33In the past I've come up with ideas for software and find that the very idea is implemented soon after. So this time rather than getting down about it I'm going to make it work for me. I'll state what I want to use and hope that its magically implemented. In order to uniformly support comments on my website I want a web service with the following features: I'm going implement this now so no one go off and do it before me so that I can use it without having to do anything...PermalinkCommentstechnical homepage

Unsolicited Mail, Telemarketing and Email: Where to Go To "Just Say No"

2007 Apr 12, 3:30The FTCs guide to opting out of telemarketing, spam, junk mail including pre approved credit card offers!PermalinkCommentsjunk mail spam optout howto

The world is in your hand | haha.nu - a lifestyle blogzine

2006 Dec 21, 3:21Cool photos of miniatures, toys, postcards or photos held up over their real world counterparts. Some look pretty cool.PermalinkCommentshumor photos blog gallery

Representing vCard Objects in RDF/XML

2006 Nov 28, 5:15This note specifies a Resource Description Framework (RDF) encoding of the vCard profile defined by RFC 2426 and to provide equivalent functionality to its standard format. The motivation is to enable the common and consistent description of persons (usinPermalinkCommentsrdf reference semanticweb specification standards w3c xml vcard schema example

Microsoft's Vision for an Identity Metasystem

2006 Nov 6, 4:34Linked from http://www.identityblog.com/. Good paper on the structure of the Identity Metasystem talked of on the identityblog.PermalinkCommentsidentity security privacy microsoft msdn article internet authentication cryptography read programming information metasystem infocard passport

Kim Cameron’s Identity Weblog

2006 Nov 6, 4:32Blog on Identity. Jim mentioned this and I'd seen it around previously. Good links to other things I've wanted to know more about like Infocard and Passport. Good thoughts on Identity in general. Very interesting.PermalinkCommentsidentity blog security privacy microsoft internet authentication cryptography programming information

Picard Song

2006 Jan 17, 10:19PermalinkCommentspicard startrek humor music video tv

Stripe Snoop :: Homepage

2005 Dec 5, 6:27PermalinkCommentsdevelopment hack hardware card
Older EntriesNewer Entries Creative Commons License Some rights reserved.