Archive for April, 2012

A cmd.exe sleep command?

SleepIt’s always a surprise when a batch file scripter realizes cmd.exe lacks a sleep command.  But fear not!  The choice command can be used as a substitute.  It lists a set of choices and waits a specified amount of time for the user to choose one.  Choice can be used to sleep for 0 to 9999 seconds (or over 2.7 hours).

Just create the following file and save it as sleep.cmd:

@echo off
set /a SleepTime = %1
CHOICE /N /D y /T %SleepTime% /M "Sleeping for %SleepTime% seconds . . ."


Place it in your aliases bin and you’re all set to sleep from the command line!

Leave a Comment

PWD for cmd.exe?

For years I’ve mourned the loss of my favorite unix shell command, pwd.  I can’t count the number of times I had typed those three  simple letters into my xterm window.  After moving to a Windows environment over 10 years ago I started anew with commands like dir instead of ls, type instead of more (wait! more works!), findstr instead of grep, etc…

But no replacement for pwd.  No worries, the prompt for cmd is the current working directory by default.  But what if you change the prompt to the date and time, like I often do (prompt $D$S$T$G), to have a history of when you types which command. That leaves you with no way to tell the current directory.

But today, I learned about the cd env variable. Echo’ing %cd% prints the current directory.  Excited by this, I created the simple batch file:

@echo off
echo %cd%\

I named it pwd.cmd and placed it in my aliases directory.


Leave a Comment