Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Bill,

The fact that Result1 is a sigma proves that the shell script did not encode the \xe4

I disagree, because the `` has some implicit translations going on that you aren't controlling.

To test it, you need to capture the raw output bytes of the -e under test. Then you can compare them to the expected values.

I show an example test where I print \xe4\xe0 twice: the first time, without a binmode in the oneliner; the second time, with a binmode in the oneliner. You can see that the bytes that are output are different. You can test that those bytes match your expectations.

C:\Users\peter.jones\Downloads\TempData\perl>chcp
Active code page: 437
C:\Users\peter.jones\Downloads\TempData\perl>perl pm.pl

__SOURCE__
#!perl

use 5.012; # strict, //
use warnings;
use IPC::Open2;
use Test::More;

undef $\;
print "\n__SOURCE__\n";
seek \*DATA, 0, 0;
print for <DATA>;

$\ = "\n";
{
    my $pid = open2(my $ofh, my $ifh, 'perl', '-e', q("print qq(\xe4\xe0)"));
    binmode $ofh, ':raw';   # need to read from the open2 output file handle in raw mode, so you're looking at bytes, _not_ characters
    chomp(my $line = <$ofh>);
    print "without binmode, the high 8-bit characters pass through untranslated: ", unpack 'H*', $line;
    is $line, "\xE4\xE0", 'the bytes should be unedited';
    print "and printed out during test script: '$line'";
}
{
    my $pid = open2(my $ofh, my $ifh, 'perl', '-e', q("binmode STDOUT, ':encoding(Cp437)'; print qq(\xe4\xe0)"));
    binmode $ofh, ':raw';   # need to read from the open2 output file handle in raw mode, so you're looking at bytes, _not_ characters
    chomp(my $line = <$ofh>);
    print "with binmode, xE4 gets translated to x84 for a-umlaut, and xE0 gets translated to x85 for a-grave: ", unpack 'H*', $line;
    is $line, "\x84\x85", 'the bytes should be CP437-encoded';
    # so here, instead of printing the hexdump of the captured line, you could compare
    print "and printed out during test script: '$line'";
}
done_testing();

__END__
__OUTPUT__
without binmode, the high 8-bit characters pass through untranslated: e4e0
ok 1 - the bytes should be unedited
and printed out during test script: 'Σα'
with binmode, xE4 gets translated to x84 for a-umlaut, and xE0 gets translated to x85 for a-grave: 8485
ok 2 - the bytes should be CP437-encoded
and printed out during test script: 'да'
1..2


In reply to Re^2: print in CMD window by pryrt
in thread print in CMD window by BillKSmith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-05-22 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?