So, I guess you're saying that there is no way to determine "where it was launched from", correct?

I suspect that other than trying to do some inspection of the process tree, the answer is no.

However, this is sounding like an XY Problem. What are you actually trying to do such that it matters where a Perl binary was launched from?

It seems to me that once a binary is launched, it will behave according to how it was compiled, not how it was launched. The only difference I could imagine would be what the command line argument array looks like and what the inherited environment is.

That might be something to try. E.g. print_env.pl:

#!C:/perl/bin/perl #!/usr/bin/perl use strict; use warnings; print "\$0: $0\n"; print "ARGV: ", join( q{,}, map { qq('$_') } @ARGV ), "\n"; print "\nEnvironment:\n"; print "$_: $ENV{$_}\n" for sort keys %ENV;

Run that from cygwin's shell and cmd.exe, try swapping around the shebang lines, etc. From cygwin's shell, try invoking it directly versus calling it as an argument to perl:

$ chmod +x print_env.pl $ ./print_env.pl one two three $ perl print_env.pl one two three

I think if you call it directly, you'll see something different in $0 than if you call it as the argument to perl. And you might see differences in %ENV. You might even set an environment variable in your cygwin .bashrc that you could use as a flag.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re^5: Test for OS version in Perl by xdg
in thread Test for OS version in Perl by rlambert7

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.