The client tool can read from stdin and produce output on stdout. For example ldapsearch -L -x -f - 'cn=%s' uid
This will read cn values from stdin and produce search results on stdout. But doing this interactively does not produce the immediate feedback because stdout is often buffered. The search results are presented only after a sufficient amount have been buffered, or an EOF is encountered.
It would be very nice if ldapsearch application would flush stdout after each search.
Below is a diff of the ldapsearch client tool with my proposed change.
*************** *** 1,5 **** /* ldapsearch -- a tool for searching LDAP directories */ ! /* $OpenLDAP: pkg/ldap/clients/tools/ldapsearch.c,v 1.234.2.9 2008/02/12 19:59:52 quanah Exp $ */ /* This work is part of OpenLDAP Software http://www.openldap.org/. * * Copyright 1998-2008 The OpenLDAP Foundation. --- 1,5 ---- /* ldapsearch -- a tool for searching LDAP directories */ ! /* $OpenLDAP: pkg/ldap/clients/tools/ldapsearch.c,v 1.234.2.9 2008/02/12 19:59:52 quanah Exp $ */ /* This work is part of OpenLDAP Software http://www.openldap.org/. * * Copyright 1998-2008 The OpenLDAP Foundation. *************** *** 998,1003 **** --- 998,1004 ---- if ( !contoper ) break; } + fflush(stdout); } if ( fp != stdin ) { fclose( fp );
Dale.Moore@cs.cmu.edu wrote:
The client tool can read from stdin and produce output on stdout. For example ldapsearch -L -x -f - 'cn=%s' uid
This will read cn values from stdin and produce search results on stdout. But doing this interactively does not produce the immediate feedback because stdout is often buffered. The search results are presented only after a sufficient amount have been buffered, or an EOF is encountered.
stdout is line buffered by default when it's attached to a terminal. I don't see any reason to change this. If it's behaving like a block-buffered handle on your system then your platform is broken.
Dale.Moore@cs.cmu.edu wrote
The client tool can read from stdin and produce output on stdout. For example ldapsearch -L -x -f - 'cn=%s' uid
This will read cn values from stdin and produce search results on stdout. But doing this interactively does not produce the immediate feedback because stdout is often buffered. The search results are presented only after a sufficient amount have been buffered, or an EOF is encountered.
Howard Chu hyc@symas.com wrote
stdout is line buffered by default when it's attached to a terminal. I don't see any reason to change this. If it's behaving like a block-buffered handle on your system then your platform is broken.
In the situation that brought this up, it was interactive, but it wasn’t interactive through a terminal. It was interactive through a pipe in a script. Of course, many systems do buffer pipes.
I hope that you now see some small amount of benefit to flushing stdout.
Dale Moore