[MDEV-6875] TEE command does not work when piped into mysql client Created: 2014-10-15  Updated: 2015-04-23

Status: Open
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 5.5.40, 10.0.14, 10.1.0
Fix Version/s: 10.1

Type: Bug Priority: Minor
Reporter: Robin J. rogge Assignee: Alexander Barkov
Resolution: Unresolved Votes: 1
Labels: client, upstream-fixed


 Description   

The following command will work as expected with Percona and Oracle MySQL 5.6 releases, but not with MariaDB 10.1: output is generated on stdout but the /tmp/foo file is not being created.

echo "TEE /tmp/foo; SHOW MASTER STATUS\G; NOTEE;" | mysql

When running the same query from within the mysql client application (as opposed to piping into it), the file will be created as expected.



 Comments   
Comment by Elena Stepanova [ 2014-10-16 ]

Reproducible on MySQL 5.5, apparently fixed in 5.6.

Assigned to bar, because here is the only commit I found in 5.6 that mentions TEE – of course, it doesn't necessarily mean it's the one, but it's a viable suspect.

   revno: 2876.368.113
    revision-id: alexander.barkov@oracle.com-20110223045307-u316hqua4z5j86xe
    parent: andrei.elkin@oracle.com-20110222155247-k07c3725arfph223
    committer: Alexander Barkov <alexander.barkov@oracle.com>
    branch nick: mysql-trunk.w5331
    timestamp: Wed 2011-02-23 07:53:07 +0300
    message:
      WL#5331 Support Unicode for Windows command line client
      
      Based on the original patch form Vladislav Vaintroub:
      http://lists.mysql.com/commits/105379
      
      
        @ client/mysql.cc
        - introducing new function tee_write(), to reuse
          in a number of places where similar loops displaying
          data occurs.
        - introducing flags for tee_write(), to support different
          printing modes, according to --xml, --raw, --tab, etc,
          parameters
        - Instead if using argv (which is always in ANSI code page),
          we now use UTF16LE API to access command line arguments on Windows,
          using this scenario:
          a. We translate arguments to UTF8MB4 on startup.
          b. Then we process arguments and detect connection character set
             from --default-character-set arguments (or my.ini value),
             or from the OS localization information by default.
          c. Then we convert user, database and the --execute (-e) buffer
             from UTF8MB4 to the connection character set.
          d. Connect
        - Instead of printing using printif/fputs family functions on Windows,
          which are limited to the current DOS code page (cp850 on a Western machine)
          we now use UTF16LE console API through the new my_win_console_xxx() 
          functions implemented in my_conio.c
        - Using mysql_set_character_set() instead of
          mysql_option(OPT_CHARACTER_SET_NAME) to know the ongoing
          session character set *before* mysql_real_connect() call,
          to convert user and database properly.
        - my_win_is_console_cached() has been added to cache
          my_win_is_console() result for stdout and stderr,
          for performance purposes.
...

Comment by Elena Stepanova [ 2014-11-16 ]

Moved to upstream-fixed because it's not reproducible on MySQL 5.6 (even if the revision above was not the one to fix it).

Comment by A. Dischner [ 2015-04-22 ]

My systems SLES 11/12 and openSUSE 13.2

mysql 5.5.2: fails
mysql 5.6.16: works
mysql 5.6.19: works
mariadb 10.0.11: fails
mariadb 10.0.17: fails

does anybody have a workaround?

regards,

Bodo

Comment by Sergei Golubchik [ 2015-04-22 ]

This is not, strictly speaking, a bug. TEE and PAGER commands don't work in the batch mode, this is intentional and documented (e.g see mysql --help). And batch mode is enabled whenever the input is not the terminal.

I'd rather say that MySQL-5.6 behavior is a bug. There was a crash when TEE was used in embedded server. It's Bug#11764633, fixed in commit d608ad2dd6. Later they've removed the check for the batch mode from the TEE command (in commit 47f7fc4353) to be able to test the fix for Bug#11764633 in the test suite. Usually debugging changes like that are only enabled in a special "testing" mode, but Oracle has unintentionally enabled TEE in batch mode for everyone. I say "unintentionally" because the help text wasn't changed and the --tee command line option still doesn't work in batch mode, so it apparently was not an intentional decision "let's enable TEE in batch mode".

Anyway, I tend to agree that this "buggy" 5.6 behavior is more practically useful than the old intentional behavior of mysql client. We can enable TEE in the batch mode.

That includes

  • enable TEE and PAGER in the batch mode
  • enable --tee and --pager in the batch mode
  • update the help text accordingly

Related useful change:

  • make it possible to disable batch mode from the command line

Alternatively, we can do just the last item (make it possible to disable batch mode) and whoever needs TEE or PAGER will have to disable batch mode to use them.

As a workaround you can use tee after the mysql client:

echo "SHOW MASTER STATUS\G" | mysql | tee /tmp/foo

Comment by A. Dischner [ 2015-04-23 ]

Hi Sergei,

thanks for your fast, in depth answer!

The workaround works perfect for me,

kind regards,

Bodo

Generated at Thu Feb 08 07:15:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.