http://qs321.pair.com?node_id=586301

To anyone who is doing development on Windows platforms...

A very common task I must do from time to time is open the command-line ("cmd") in some directory. The path I usually take is run "cmd" via Start -> Run and then copy and paste the directory path into it, with an appropriate "cd". Of course, Windows' drive rules suck and in addition to the "cd" you must sometimes make it change a drive by typing "c:" or "d:".

Today I found a solution. It's so simple and obvious I can't imagine how I didn't see it before. I wrote a Perl script that reads what's in the clipboard buffer and just runs 'cmd' with an appropriate drive change and "cd" into that directory. Placing a shortcut to the script into the Quicklaunch bar makes opening "cmd" in the desired place only one Ctrl-C and one mouse click away. It doesn't get shorter than this :-)

Anyway here is the script:

use warnings; use strict; $|++; use Win32::Clipboard; # Take the path from the clipboard # my $clip = Win32::Clipboard(); my $path = $clip->Get(); # Does it look like a valid path ? # if ($path !~ /^([a-z]) :/xi) { die "$path\ndoesn't look like a path\n"; } # The drive letter must be gathered separately to issue a drive # change command # my $drive = $1; my $BAT_FILENAME = 'crun.bat'; open(my $ofh, ">", $BAT_FILENAME) or die $!; print $ofh "${drive}:\n"; print $ofh "cd $path\n"; print $ofh "cmd\n"; close($ofh); # Run ! # system($BAT_FILENAME);

One question though... I recall that on Unixes one can create a child and then detach it, allowing the parent process to exit with the child staying alive. Is there a way to do it on Windows ? The problem with this script is that a perl process stays alive while the "cmd" window is open. It doesn't take any CPU so it's not a big deal, but still I yearn for something cleaner. Any ideas ?