Bug #7553 Read StdIn only when EOF ?
Submitted: 28 Dec 2004 9:22 Modified: 28 Dec 2004 13:34
Reporter: Fabio Fernandes Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.1.8 OS:Windows (windows 2000 Pro)
Assigned to: CPU Architecture:Any

[28 Dec 2004 9:22] Fabio Fernandes
Description:

When i try to control de command line ( muysql.exe ) by pipes ( StdIn/StdOut ) with resident instance of execution, the mysql.exe do not process commands
until i send "EOF" why ?

ex : 

( with windows api )

1. create pipes for StdIn/StdOut.StdErr...
2. duplicate pipes for read and write...
3. create process ( mysql.exe ) detached,suspended...
4. run the main thread..

5. write in pipe for StdInt, like...

  5.a Write "SELECT * FROM XYZ ; " + #13#10 ( nothing in StdOut )

  5.b Write "SELECT * FROM XYZ ; " + #13#10#EOF  ( ok in StdOut )

  Why ? EOF ? Just process closed files ?

Tks for your atention 
I just send this because can not find this in documentation.
If this is not a bug, sorry, but i need the documentation about
read and write pipes process of mysql.exe, because with other clients
of other databases i dont have problem with the same code.

Fábio Fernandes
Brazil

How to repeat:

Suggested fix:

Read the StdIn line by line, like any other.
[28 Dec 2004 9:56] Joerg Bruehe
You have to check the Windows API documentation for this.
Typically, a C runtime library and an operating system will both buffer I/O for efficiency reasons. So if you want to use pipes for communication between co-processes, you have to ensure that 
1) your application writes its commands _unbuffered_ into the pipe (in C, typically output is buffered unless it is to a terminal, so pipe output would be buffered - please check for Windows);
2) the command pipe is not by default buffered in the operating system;
3) the result pipe is not buffered;
4) your application gets results immediately, even if the result pipe is not yet full.

I assume item 1) to be the most important one.

If you have any doubts, try the same setup with a dummy process replacing the MySQL server, that dummy process should just read commands from one pipe and reply something on the other. Only if that works, replace the dummy by the MySQL server and try again.
[28 Dec 2004 10:32] Sergei Golubchik
and don't forget to run mysql with -n switch (see mysql --help for details)
[28 Dec 2004 10:48] Fabio Fernandes
Thanks for all, i will check my code NOW and send feedback
very soon.
[28 Dec 2004 10:59] Fabio Fernandes
My code to handle pipes ok, just "-n" in client and StdOut ready !
Thanks again !
[28 Dec 2004 13:34] Alexander Keremidarski
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php