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 ?


In reply to Invoking the Windows command line for selected directories by spurperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.