I'm a big fan of opening the Command Prompt in Windows and entering a single command line to run a script e.g.
C:\WINDOWS>perl c:\mydocu~1\david\somescript.pl
Now, problem with this is that it sets as the current working directory the directory (e.g. C:/WINDOWS/) I launched the command from, rather than the directory (e.g. C:/My Documents/David/) where the script resides, which I would like to have on hand in order to play with other files that live in its neighbourhood. I guess I'd also like to have fully portable code that's prepared for any reasonable method of launch, and so I think this is an issue that can't be resolved just by changing my own behaviour. Previously I was using Windows 98SE and I'd gone some way to solving the problem by stripping the script path from
$ENV{"CMDLINE"}
... but now I'm using Windows XP, which don't got
$ENV{"CMDLINE"}
or anything similar! Is there any consistent way of getting the full shell command line, or more generally of getting a script to find itself on the file system? Also, what issues does this have for portability to non-Windows OSs?

In reply to Having a script find itself on the file system in Windows XP and other OSs by David Catchpole

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.