Apparently, a Perl script I have results in two different output files depending on if I run it under Windows PowerShell, or cmd.exe. The script can be found at the bottom of this question. The file handle is opened with IO::File
, I believe that PerlIO is doing some screwy stuff. It seems as if under cmd.exe
the encoding chosen is much more compact encoding (4.09 KB), as compared to PowerShell which generates a file nearly twice the size (8.19 KB). This script takes a shell script and generates a Windows batch file. It seems like the one generated under cmd.exe
is just regular ASCII (1 byte character), while the other one appears to be UTF-16 (first two bytes FF FE
)
谁能核实和解释为什么PerlIO在Windows Powerhell下的工作不同于厘米。 另外,我如何使用<代码>IO:File明确获取ASCII-magic PerlIO文档。
目前,只有<代码>cmd.exe生成的文件才能执行。 UTF-16 .bat
(我认为,编码不能由PowerShell或cmd.exe执行。)
BTW, we re use Perl 5.12.1 for MSWin32
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use IO::File;
use IO::Dir;
use feature :5.10 ;
my $bash_ftp_script = File::Spec->catfile( bin , dm-ftp-push );
my $fh = IO::File->new( $bash_ftp_script, r ) or die $!;
my @lines = grep $_ !~ /^#.*/, <$fh>;
my $file = join , @lines;
$file =~ s/ \
/ /gm;
$file =~ tr/ /"/d;
$file =~ s/ +/ /g;
$file =~ s/"|"/"/g;
my @singleLnFile = grep /ncftp|echo/, split $/, $file;
s/$PWD///g for @singleLnFile;
my $dh = IO::Dir->new( . );
my @files = grep /.pl$/, $dh->read;
say echo off ;
say "perl $_" for @files;
say for @singleLnFile;
1;