Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

ipconfig /?|hexdump 00000000: 0D 0D 0A 55 53 41 47 45 - 3A 0D 0D 0A 20 20 20 20 | USAGE: + | 00000010: 69 70 63 6F 6E 66 69 67 - 20 5B 2F 3F 20 7C 20 2F |ipconfig +[/? | /| 00000020: 61 6C 6C 20 7C 20 2F 72 - 65 6E 65 77 20 5B 61 64 |all | /re +new [ad| 00000030: 61 70 74 65 72 5D 20 7C - 20 2F 72 65 6C 65 61 73 |apter] | +/releas| 00000040: 65 20 5B 61 64 61 70 74 - 65 72 5D 20 7C 0D 0D 0A |e [adapte +r] | | 00000050: 20 20 20 20 20 20 20 20 - 20 20 20 20 20 20 2F 66 | + /f| 00000060: 6C 75 73 68 64 6E 73 20 - 7C 20 2F 64 69 73 70 6C |lushdns | + /displ| 00000070: 61 79 64 6E 73 20 7C 20 - 2F 72 65 67 69 73 74 65 |aydns | / +registe| 00000080: 72 64 6E 73 20 7C 0D 0D - 0A 20 20 20 20 20 20 20 |rdns | + |
You can see 0D 0D 0A repeatedly. chcp says cmd.exe is using cp437
cmd.exe and notepad don't show extra newlines.
Is it an actual encoding or just errant output?

Here is a perlio solution

open IN, '-|:raw:crlf', 'ipconfig /?' ... open OUT', '>:raw' ..

Replies are listed 'Best First'.
Re: ipconfig output encoding ( 0D 0D 0A ) ("newlines"?)
by tye (Sage) on Feb 09, 2008 at 07:03 UTC
    notepad don't show extra newlines

    Because there aren't any extra newlines. There is an extra carriage return. Probably just somebody wrote print "...\r\n"; for whatever reason and the Win32 C RTL layer turned "\n" into "\r\n" giving "\r\r\n".

    Just another reason to ignore trailing whitespace on the ends of lines. Use s/\s+$//; instead of chomp. It makes for better-behaved programs.

    - tye        

Re: ipconfig output encoding ( 0D 0D 0A )
by GrandFather (Saint) on Feb 09, 2008 at 06:51 UTC

    A bug in ipconfig is my guess. If you try the same thing with dir the line ends are fine which pretty much precludes cmd trashing the line ends.

    You could do the cleanup with:

    ipconfig /? | perl -np -e "$_ =~ s![\x0d\x0a]!!gm;" -e "$_ .= qq(\n);" + | hexdump

    Perl is environmentally friendly - it saves trees
Re: ipconfig output encoding ( 0D 0D 0A )
by jrtayloriv (Pilgrim) on Feb 09, 2008 at 06:48 UTC
    EDIT: oops! Not paying attention ...