1

If I run this script:

use Cwd;
print "$^O\n";
print cwd;

The output is:

C:\tmp>perl tmp.pl
msys
/c/tmp

How can I get windows style path C:\tmp?

Pawel P.
  • 3,731
  • 4
  • 20
  • 20
  • possible duplicate of [Using Perl on Windows, how can I ensure I get the path in the correct case following a chdir?](http://stackoverflow.com/questions/7995113/using-perl-on-windows-how-can-i-ensure-i-get-the-path-in-the-correct-case-follo) – devnull Sep 17 '13 at 08:52
  • @devnull: Not really a duplicate, IMO, even if the answer given to the other question (i.e. `Win32::GetLongPathName()`) might indeed help here too. (OTOH, this _could_ be considered a duplicate of [this question](http://stackoverflow.com/questions/922221/perl-getcwd-ending-forward-slashes).) – Ilmari Karonen Dec 16 '13 at 22:25

2 Answers2

4

It's because you're using built-in perl of msys, and this version of perl will definitely give a Linux-style path. If you installed Active Perl and use Active Perl to launch your script, the path would be Win32-style:

$ /bin/perl5_8.exe path.pl
msys
/c/tmp

$ /c/ActivePerl/bin/perl.exe path.pl
MSWin32
c:/tmp

You could use alias in your bash profile to redirect perl to ActivePerl:

alias perl /c/ActivePerl/bin/perl.exe

Then:

$ which perl
perl is /c/ActivePerl/bin/perl
Logan Ding
  • 1,761
  • 1
  • 12
  • 23
2

You're not really on Windows, or $^O would be MSWin32. You're inside the MSYS unix emulation environment, so it's no surprise you have unix-style paths. For a version of Perl that runs on Windows natively, use ActivePerl or Strawberry Perl.

ikegami
  • 367,544
  • 15
  • 269
  • 518