code_junkie

How do I get the full path to a Perl script that is executing?

Nov 10th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. use Cwd 'abs_path';
  2. print abs_path($0);
  3.  
  4. use File::Basename;
  5. my $dirname = dirname(__FILE__);
  6.  
  7. #!/usr/bin/perl
  8. use FindBin;
  9.  
  10. $0 = "stealth";
  11. print "The actual path to this is: $FindBin::Bin/$FindBin::Scriptn";
  12.  
  13. use Cwd qw(abs_path);
  14. my $path = abs_path($0);
  15. print "$pathn";
  16.  
  17. $ENV{'SCRIPT_NAME'}
  18.  
  19. use FindBin '$Bin';
  20. print "The script is located in $Bin.n";
  21.  
  22. use strict ; use warnings ; use Cwd 'abs_path';
  23. sub ResolveMyProductBaseDir {
  24.  
  25. # Start - Resolve the ProductBaseDir
  26. #resolve the run dir where this scripts is placed
  27. my $ScriptAbsolutPath = abs_path($0) ;
  28. #debug print "$ScriptAbsolutPath is $ScriptAbsolutPath n" ;
  29. $ScriptAbsolutPath =~ m/^(.*)(\|/)(.*).([a-z]*)/;
  30. $RunDir = $1 ;
  31. #debug print "$1 is $1 n" ;
  32. #change the 's to /'s if we are on Windows
  33. $RunDir =~s/\///gi ;
  34. my @DirParts = split ('/' , $RunDir) ;
  35. for (my $count=0; $count < 4; $count++) { pop @DirParts ; }
  36. my $ProductBaseDir = join ( '/' , @DirParts ) ;
  37. # Stop - Resolve the ProductBaseDir
  38. #debug print "ResolveMyProductBaseDir $ProductBaseDir is $ProductBaseDir n" ;
  39. return $ProductBaseDir ;
  40. } #eof sub
Add Comment
Please, Sign In to add comment