显然,我的 Perl 脚本会产生两个不同的输出文件,具体取决于我是在 Windows PowerShell 还是 cmd.exe 下运行它。该脚本可以在这个问题的底部找到。文件句柄以 . 打开IO::File
,我相信 PerlIO 正在做一些棘手的事情。cmd.exe
与生成几乎两倍大小的文件 (8.19 KB) 的 PowerShell 相比,似乎在选择的编码下是更紧凑的编码 (4.09 KB)。该脚本采用一个 shell 脚本并生成一个 Windows 批处理文件。似乎在下面生成cmd.exe
的只是常规 ASCII(1 字节字符),而另一个似乎是 UTF-16(前两个字节FF FE
)
有人可以验证并解释为什么 PerlIO 在 Windows Powershell 下的工作方式与 cmd.exe 不同吗?另外,如何使用 ASCII 魔术 PerlIO 文件句柄显式获取IO::File
?
目前,只有生成的文件cmd.exe
是可执行的。UTF-16 .bat
(我认为这是编码)不能由 PowerShell 或 cmd.exe 执行。
顺便说一句,我们将 Perl 5.12.1 用于 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/ \\\n/ /gm;
$file =~ tr/'\t/"/d;
$file =~ s/ +/ /g;
$file =~ s/\b"|"\b/"/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;