When trying to use the more, tail and exec commands with output redirection using binary files the written content is invalid.
Examples:
more /tmp/file.mp3 > /tmp/file_out.mp3
file_out.mp3 is not playable, it works if executing the same command in Bash
tail -100 /tmp/file.mp3 > /tmp/file_out.mp3
the same as above, here make sure that the indicated number is big enough so it doesn't truncate the file
exec more /tmp/file.mp3 > /tmp/file_out.mp3
Please note that the cat, tee and grep commands are working fine in similar situations:
cat /tmp/file.mp3 > /tmp/file_out.mp3
cat /tmp/file.mp3 | tee > /tmp/file_out.mp3
grep "" /tmp/file.mp3 > /tmp/file_out.mp3 (equivalent in Bash: grep -a "" /tmp/file.mp3 > /tmp/file_out.mp3)
---
Related issues:
Issue #7014 - Passing binary file to more and tail caused NPE in Term
Issue #7009 - NPE on cat command
Issue #6853 - Cat multiple mp3 files & streaming output to another mp3 file generates an invalid file
The reason \cat, \tee and \grep work is because these commands handle I/O in 'byte'. \more and \tail currently read/write I/O in 'String' which won't work in your test cases. \more and \tail need to be modified to perform 'byte' I/O in order to cover your test cases (writing output in byte has been taken care of by issue #7014, reading input in byte is not).
The current implementation of \more always add an empty line at the end if the size of the given file is not zero. This needs to be fixed; otherwise the test case 'more file.txt > file.txt.copy' would never pass.
The current implementation of \more always add an empty line at the end if the size of the given file is not zero. This needs to be fixed; otherwise the test case 'more file.txt > file.txt.copy' would never pass.
\tail, \exec, and \more have been modified to handle I/O in bytes (SVN r28100, r28101, and r28102).
I had tried the following test cases work on Windows, and then run cygwin's diff to compare the results:
tail -1000000 binary-file > tmp.bin ; diff binary-file tmp.bin (no difference)
tail -1000000 text-file > tmp.txt ; diff text-file tmp.txt (no difference)
more binary-file > tmp.bin ; diff binary-file tmp.bin (no difference)
more text-file > tmp.txt ; diff text-file tmp.txt (no difference)
exec tail -1000000 binary-file > tmp.bin ; diff binary-file tmp.bin (no difference)
exec tail -1000000 text-file > tmp.txt ; diff text-file tmp.txt (no difference)
I was not able to get the followings work on Windows:
exec more binary-file > tmp.bin ; diff binary-file tmp.bin (does not match)
exec more text-file > tmp.txt ; diff text-file tmp.txt (does not match)
This is because Windows' more command generate file header (3-line header at the very beginning) along with output.
However, if I strip the header lines from the generated file using fluid \tail command, then do a diff, the result is the same:
tail -n +4 tmp.bin > tmp.bin.1 ; diff binary-file tmp.bin.1 (no difference)
tail -n +4 tmp.txt > tmp.txt.1 ; diff text-file tmp.txt.1 (no difference)
And, of course, \more won't generate an extra empty line any more. In addition, \more did not generate output correctly when 2 or more files specified and multiple pages are generated. It is fixed as well.
\tail, \exec, and \more have been modified to handle I/O in bytes (SVN r28100, r28101, and r28102).
I had tried the following test cases work on Windows, and then run cygwin's diff to compare the results:
tail -1000000 binary-file > tmp.bin ; diff binary-file tmp.bin (no difference)
tail -1000000 text-file > tmp.txt ; diff text-file tmp.txt (no difference)
more binary-file > tmp.bin ; diff binary-file tmp.bin (no difference)
more text-file > tmp.txt ; diff text-file tmp.txt (no difference)
exec tail -1000000 binary-file > tmp.bin ; diff binary-file tmp.bin (no difference)
exec tail -1000000 text-file > tmp.txt ; diff text-file tmp.txt (no difference)
I was not able to get the followings work on Windows:
exec more binary-file > tmp.bin ; diff binary-file tmp.bin (does not match)
exec more text-file > tmp.txt ; diff text-file tmp.txt (does not match)
This is because Windows' more command generate file header (3-line header at the very beginning) along with output.
However, if I strip the header lines from the generated file using fluid \tail command, then do a diff, the result is the same:
tail -n +4 tmp.bin > tmp.bin.1 ; diff binary-file tmp.bin.1 (no difference)
tail -n +4 tmp.txt > tmp.txt.1 ; diff text-file tmp.txt.1 (no difference)
And, of course, \more won't generate an extra empty line any more. In addition, \more did not generate output correctly when 2 or more files specified and multiple pages are generated. It is fixed as well.
>>>> In addition, \more did not generate output correctly when 2 or more files specified and multiple pages are generated. It is fixed as well.
FYI, the test case is 'more file1 file2...':
If \more generates 2+ pages, and the first page contains contents from 2 or more files, then you will find that the first page was not generated correctly, its contents gets shift up, i.e. the number of rows contained in the first page is larger than the screen size.
>>>> In addition, \more did not generate output correctly when 2 or more files specified and multiple pages are generated. It is fixed as well.
FYI, the test case is 'more file1 file2...':
If \more generates 2+ pages, and the first page contains contents from 2 or more files, then you will find that the first page was not generated correctly, its contents gets shift up, i.e. the number of rows contained in the first page is larger than the screen size.
Using ADStudio 12 Dev 114, verified the cases for more, tail and exec; all are working fine now.
Calling exec more file > file2 under Ubuntu from FluidShell also generates a header, however the header doesn't get generated if calling the same cmd from Bash; will investigate further and if necessary will open a separate issue.
Changed status to Closed.
Using ADStudio 12 Dev 114, verified the cases for more, tail and exec; all are working fine now.
Calling exec more file > file2 under Ubuntu from FluidShell also generates a header, however the header doesn't get generated if calling the same cmd from Bash; will investigate further and if necessary will open a separate issue.
Changed status to Closed.
Issue #7174 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
Fixed Build trunk/28102 |
No time estimate |
1 issue link |
relates to #7586
Issue #7586Performance problem on commands that read in file contents in byte[] |
The reason \cat, \tee and \grep work is because these commands handle I/O in 'byte'. \more and \tail currently read/write I/O in 'String' which won't work in your test cases. \more and \tail need to be modified to perform 'byte' I/O in order to cover your test cases (writing output in byte has been taken care of by issue #7014, reading input in byte is not).