echo5 has asked for the wisdom of the Perl Monks concerning the following question:
I have a simple script that appears to show that some byte in the output is causing Perl to behave strangely.
The script calls a command that coughs up 150 bytes or so of binary data. One stream of returned data behaves as expected. Another stream causes chaos.
The script: $cmd = "/usr/local/bin/mycmd"; print "The cmd to be run is: $cmd \n"; open(CMD, "$cmd |" ) or die "Can't run '$cmd'\n$!\n"; while (<CMD>) { chomp; print "My raw output is: $_ \n"; $dataout = $_; print "My DATAOUT is: $dataout \n"; }
When I run the above script in a "good" scenario I get the below output:
The cmd to be run is: /usr/local/bin/mycmd My raw output is: � ` /11�%_$�%f$�&c$A +533;%a$�%\$&c$&^$�&i$ My DATAOUT is: � ` /11�%_$�%f$�&c$� +%a$�%\$&c$&^$�&i$
When I run the above script in a "bad" scenario I get the below output:
The cmd to be run is: /usr/local/bin/mycmd My raw output is: My DATAOUT is: My raw output is: �0]�c �� My DATAOUT is: �0]�c ��
Ultimately the goal is to ingest the data and process it using unpack but that was failing as $_ didn't contain data is should contain to process. The "bad" behavior above seems to show that there is some sort of "killer byte" being output from mycmd that throws a wrench into things. Below is the good and bad output in hex form via xxd. Is there a byte in there tripping up Perl?
Good data stream: 0000000: 0202 00d0 0000 0000 0000 0000 0100 0000 ................ 0000010: 0100 0000 0100 0000 0100 0000 0100 0000 ................ 0000020: 0100 0000 0100 0000 0500 0000 0500 0000 ................ 0000030: 0500 0000 0500 0000 0500 0020 0100 0000 ........... .... 0000040: 0100 0000 0100 0000 0100 0000 0100 0000 ................ 0000050: 0100 0000 0100 0000 0500 0000 0500 0000 ................ 0000060: 0500 0000 0100 0000 0100 0000 0000 0000 ................ 0000070: 0200 0060 0100 0020 0000 0000 0100 2d00 ...`... ......-. 0000080: 0100 2f00 0100 3000 0000 0000 0100 0000 ../...0......... 0000090: 0000 0000 0102 ca25 0102 4a24 0102 bd25 .......%..J$...% 00000a0: 0102 5024 0102 da25 0102 4c24 0102 d525 ..P$...%..L$...% 00000b0: 0102 4c24 0102 c325 0102 4624 0102 e025 ..L$...%..F$...% 00000c0: 0102 4e24 0102 e225 0102 4824 0102 dd25 ..N$...%..H$...% 00000d0: 0102 5224 ..R$
Bad data stream: 0000000: 020a 009c 0000 0000 0000 0000 0100 0000 ................ 0000010: 0100 0000 0100 0000 0100 0000 0100 0000 ................ 0000020: 0100 0000 0100 0000 0100 0000 0500 0000 ................ 0000030: 0500 0000 0500 0000 0500 0000 0500 0000 ................ 0000040: 0500 0000 0500 0000 0500 0000 0500 0000 ................ 0000050: 0500 0000 0500 0000 0500 0000 0500 0000 ................ 0000060: 0500 0000 0500 0000 0100 0000 0000 0000 ................ 0000070: 0100 3000 0000 0000 0100 005c 0100 00b4 ..0........\.... 0000080: 0000 0000 0100 0000 0000 0000 0200 0063 ...............c 0000090: 0100 0020 0000 0000 0103 9206 0103 8506 ... ............
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Killer byte tripping up Perl?
by haukex (Archbishop) on Dec 12, 2018 at 22:56 UTC | |
|
Re: Killer byte tripping up Perl?
by haj (Vicar) on Dec 12, 2018 at 22:51 UTC | |
|
Re: Killer byte tripping up Perl?
by Laurent_R (Canon) on Dec 12, 2018 at 22:55 UTC | |
|
Re: Killer byte tripping up Perl?
by stevieb (Canon) on Dec 12, 2018 at 22:36 UTC |