Re: -e on windows giving error
by BrowserUk (Patriarch) on Nov 17, 2011 at 23:28 UTC
|
my objective here is to get the drive which my perl script lies in,
If you inspect the built-in variable, $0 (that's zero not oh), it will tell you the full path of the current script including the drive. Eg:
print $0;;
C:\Perl64\bin\p1.pl
So, my( $drive ) = $0 =~ m[^(.)]; will give you the drive letter directly.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
|
Oh man, thank you so much everyone! I have found my solution and learned a lot today, Im new to perlmonks and already find the community very welcoming and helpfull!
thanks and best wishes,
Rudy
| [reply] |
|
If for some obscure reason you do not use file associations to invoke your scripts, and are in the habit of using tortuous relative path constructions to find them, then a simple step would sort out the mess you (probably didn't) create:
c:\test>perl ..\tmp\..\test\..\Perl64\site\.\lib\..\..\bin\p1.pl
Perl> print scalar Win32::GetFullPathName( $0 );;
c:\Perl64\bin\p1.pl
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
|
The solution BrowserUk rarely works. It requires an absolute path when launching the script (common for some, rare for others), and then only if the absolute path starts with something of the form "D:" (extremely common).
I've posted a more robust version here. It handles relatives paths, and even more exotic drive volume names.
| [reply] |
|
|
Re: -e on windows giving error
by ikegami (Patriarch) on Nov 17, 2011 at 23:06 UTC
|
I get no such popup.
Who built your Perl? What version is it? (I used ActivePerl v5.14.0.) I think there's a system call that configures the behaviour. (I can't remember what it's called.) There could be differences between our builds in how it's called.
Why kind of drive causes the popup? (I have a CD drive but no diskette drive.)
By the way, ever hear of loops? They are used to avoid having long lists of nearly identical code.
Update: Forgot to address your actual goal!
my objective here is to get the drive which my perl script lies in
use Path::Class qw( file );
my $vol = file($0)->absolute()->volume();
$vol = "$1:" if $vol =~ /^(?:\\\\\?\\)?([a-zA-Z])\z/;
$vol = uc($vol) if $vol =~ /^[a-zA-Z]:\z/;
| [reply] [d/l] |
Re: -e on windows giving error
by runrig (Abbot) on Nov 17, 2011 at 23:13 UTC
|
| [reply] |
|
well I am using activePerl, and whenever a drive does not exist it causes the popup each time untill it gets to the drive that does exist. and yeah I will loop it haha, thanks
I am trying to use SetErrorMode() from Win32API::File but I keep getting the error of undefined subroutine at the function call..
| [reply] |
|
Either use the fully-qualified name of the function, or import it in the use statement.
# Either this:
use Win32API::File;
my $uOldMode = Win32API::File::SetErrorMode( $uNewMode );
# or this:
use Win32API::File qw( SetErrorMode );
my $uOldMode = SetErrorMode( $uNewMode );
| [reply] [d/l] [select] |
|
use Win32API::File qw( SetErrorMode SEM_NOOPENFILEERRORBOX );
SetErrorMode( SetErrorMode(0) | SEM_NOOPENFILEERRORBOX );
| [reply] [d/l] [select] |
Re: -e on windows giving error
by Util (Priest) on Nov 17, 2011 at 23:18 UTC
|
Reorder your letters to put 'A' at the end. This is an improvement, not a perfect solution; you will only get the pop-up if `extracted` is not found at all.
sub get_drive {
for my $letter ( 'B' .. 'Q', 'A' ) {
return "$letter:" if -e "$letter:/extracted";
}
return;
}
| [reply] [d/l] |