http://www.perlmonks.org?node_id=1047236

sam_bakki has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

OS: Windows7
Perl : Active Perl 5.16, x86

C:\>set TMPDIR=C:\Temp C:\>set TEMP=C:\Temp C:\>perl -MFile::Spec -e "print File::Spec->tmpdir();" \ C:\>perl -MFile::Spec -e "print $File::Spec::VERSION;" 3.40

I expect C:\Temp but it is giving \. Am I doing something stupid or do you also face issue with File::Spec?

Thanks & Regards,
Bakkiaraj M
Perl Gtk2 technology demo project - http://code.google.com/p/saaral-soft-search-spider/ , contributions are welcome.

Replies are listed 'Best First'.
Re: File::Spec tmpdir() is behaving wrongly in Windows7
by sundialsvc4 (Abbot) on Jul 31, 2013 at 13:15 UTC

    A read of the docs in File::Spec::Win32 leads me to this quote:

    Returns a string representation of the first existing directory from the following list:

    $ENV{TMPDIR}
    $ENV{TEMP}
    $ENV{TMP}
    SYS:/temp
    C:\system\temp
    C:/temp
    /tmp
    /

    I know that Windows environment-variables are defined in a control-panel.   With a little bit of sleuthing through this information, you ought to be able to identify and resolve the problem ... ?

      And a thought for the out-of-box folks: It is possible, under certain environments, that the directory exists but the account running the script might not have sufficient access to see it. It would therefore "not exist" from the runtime perspective.

      Not allowed to ask how I know this can be an issue. :-(

      Hi sundialsvc4

      To avoid confusion, I set the environment variable SET TMPDIR=C:\Temp and then ran the perl code. Still I get the wrong results.
      C:\Temp is avilable with full permission to all users.
      I have created perlApp (Active State based) exe and executed in other machines, I face the same isse with File::Spec.
      What I understand with all the monks post is, it is File::Spec issue. I will reinstall perl freshly and try again.

      Thanks & Regards,
      Bakkiaraj M
      My Perl Gtk2 technology demo project - http://code.google.com/p/saaral-soft-search-spider/ , contributions are welcome.

        Hi sundialsvc4

        Great. Thanks for your support. Issue is solved. Looks like my C:\Temp was created by system, though it exists with write permission some how perl is not getting permission to work in it. So I have set Temp dir in my local account like below,

        C:\> SET TMPDIR=C:\Users\bakki\AppData\Local\Temp C:\> perl -MFile::Spec -e "print File::Spec->tmpdir();" C:\Users\bakki\AppData\Local\Temp

        Now everything work. Actually, it the default Temp set by windows for every user, I have modified it to point to System temp which is wrong.

        Thanks & Regards,
        Bakkiaraj M
        My Perl Gtk2 technology demo project - http://code.google.com/p/saaral-soft-search-spider/ , contributions are welcome.

Re: File::Spec tmpdir() is behaving wrongly in Windows7
by ww (Archbishop) on Jul 31, 2013 at 12:54 UTC

    Can't reproduce your problem w/Win7 and ActiveState's ...perl 5, version 16, subversion 2 (v5.16.2) built for MSWin32-x86-multi-thread:

    C:\ww>set TMPDIR=C:\Temp C:\C:\ww>set TEMP=C:\Temp C:\ww>>perl -MFile::Spec -e "print File::Spec->tmpdir();" C:\ww\AppData\Local\Temp C:\ww>>perl -MFile::Spec -e "print $File::Spec::VERSION;" 3.39_02
    If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
Re: File::Spec tmpdir() is behaving wrongly in Windows7
by MidLifeXis (Monsignor) on Jul 31, 2013 at 13:33 UTC

    Does C:\Temp exist? The documentation states that tmpdir "Returns a string representation of the first existing [emphasis added] directory..."

    Update: sundialsvc4 got to it first. :-)

    --MidLifeXis