in reply to backticks on windows (ActiveState)

It seems to me like a bug in the ActiveState Perl path separator translation. I don't know if it has been fixed on later versions of ActiveState Perl releases, but my version 5.8.0 does not seem to translate the / path separator in `` or qx to \. And I was getting incorrect command format errors.

There are many work arounds. The method I prefer is to use the Win32::AbsPath module that comes with your ActiveState perl installation to normalize the pathnames into native Windows format.
use strict; if ($^O eq "MSWin32") { require Win32::AbsPath; # load Win32::AbsPath if under Windows } sub NormalizePath # normalize/fix the path { # if on a Windows platform my $path = shift; $path = Win32::AbsPath::Fix $path if $^O eq "MSWin32"; return $path; } my $command = NormalizePath('C:/Windows/System32/cmd.exe'); my $dir = `$command /C dir`; print "$dir";
Update: jacques below has mentioned about File::Spec::Functions, which is a cleaner approach than using Win32::AbsPath. Here's an example using the File::Spec::Functions module -

use strict; use File::Spec::Functions; my $command = canonpath('C:/Windows/System32/cmd.exe'); my $dir = `$command /C dir`; print $dir;

Replies are listed 'Best First'.
Re: Re: backticks on windows (ActiveState)
by jacques (Priest) on Nov 26, 2003 at 02:11 UTC
    You shouldn't use Win32::AbsPath. Use File::Spec::Functions, which is a core module. It does the same thing. Unfortunately, Jenda makes no mention of this in the pod.
Re: Re: backticks on windows (ActiveState)
by christineandbucket (Initiate) on Nov 26, 2003 at 20:53 UTC
    Thanks so much. If I can't find a setting for ActiveState that would allow path separators to be interpreted in the backtick command, I'll get one of these workarounds going.

    The problem is that I have several hundred scripts that need to be fixed in this manner, (and while I'm sure I could do the whole lot with a little perl script), I know these all ran on ActiveState before, and so I'd rather go that route, if possible. So, I'd still like to hear if anyone knows how to get ActiveState to behave this way...