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.
|