English 中文(简体)
PerlIO inWindows PowerShell and CMD.exe
原标题:PerlIO in Windows PowerShell and CMD.exe

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;
最佳回答

我认为,你把你手稿的输出重新定位为批量文件吗? (不熟悉Perl)

如有必要,请:

perl script.pl | out-file -encoding ASCII script.bat
问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签