You get "tput: No value for $TERM and no -T specified" - we don't care about nicely wrapping columns in any case where a terminal is not available (such as crontab), and the additional output causes cron to report each run (unless you direct errors to /dev/null), so the simplest fix is simply to skip the tput COLUMNS export if TERM is zero length.

Please check out the attached patch - I will probably go ahead and commit it unless anyone has any objections.

Comments

moshe weitzman’s picture

Agree that this is annoying. My one thought is that we once had some code that suppressed this error but we had to back it out because it broke something somewhere. I searched but couldn't find the issue. Maybe one of the Aegir guys remembers (anarcat?). Anyway, seems like a good patch to me.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

that prior rollback was unrelated.

moshe weitzman’s picture

Status: Reviewed & tested by the community » Fixed

Committed. thanks owen.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jm.federico’s picture

I was still getting the notice so I did one modification to the logic:

changed

if [ -z $COLUMNS ] && [ -n "$TERM" ]; then

to

if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ $TERM != "dumb" ]; then

For some reason $TERM is set to dumb in some cases. I'm using ubuntu 8.04 (not in my hands to upgrade).

starbow’s picture

I am having the same issue as jm.federico, but on CentOS 5.4. During the crontab run $TERM is set to 'dumb'.

patrick2000’s picture

Status: Closed (fixed) » Needs review

I also have the same issue like jm.federico

my 5cts to find out why:

$ (echo $TERM; unset TERM; bash -c 'echo $TERM')
screen
dumb
$ find | xargs grep TERM 
./includes/environment.inc:  $nocolor = (drush_get_option(array('nocolor'), FALSE) || !getenv('TERM'));
./drush:if [ -z $COLUMNS ] && [ -n "$TERM" ]; then

and a quick-fix:

$ cvs diff -u drush
Index: drush
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush,v
retrieving revision 1.20
diff -u -r1.20 drush
--- drush       17 Jun 2010 04:39:41 -0000      1.20
+++ drush       7 Sep 2010 10:20:11 -0000
@@ -28,6 +28,8 @@
     SCRIPT_PATH=$(cygpath -w -a -- "$SCRIPT_PATH") ;;
 esac
 
+[ "$TERM" = dumb ] && unset TERM
+
 # If not exported and term is set determine and export the number of columns.
 if [ -z $COLUMNS ] && [ -n "$TERM" ]; then
   # Note to cygwin users: if you are getting "tput: command not found", 
greg.1.anderson’s picture

Component: Code » Base system (internal API)
Status: Needs review » Closed (duplicate)

#784342: Drush should't use colors if there is no terminal attached should also fix this; re-open if it does not.

patrick2000’s picture

Status: Closed (duplicate) » Active
StatusFileSize
new857 bytes

No, sorry, #784342 doesn't fix this issue here.

Also, I think the test weather stdout is "not a terminal" ([ ! -t 1 ]) is not the best thing to base the "--nocolor" decision on. What if somebody does $ drush | less -R (-R for "Raw control chars" - makes color codes work in the less pager). In that case the colors will be suppressed because stdout will be a pipe while the user actually intended to have colors enabled. And besides that i don't like the "set -- ..." line, that changes the effective command line arguments, at all. That sort of manipulations can make debugging really hard.

Checking the TERM variable for being "not present" OR "'dumb'" is better, I think. It has already been done this way. It was just not "done right", because TERM was only tested for being "not present" and checking for "dumb" was neglected. As bash sets "TERM" to "dumb" on startup if it is not present, this is necessary. Switching to [ -t 1 ] type testing now would be inconsistent with existing code.

See the attached proposed patch, which implements my suggested changes.

patrick2000’s picture

StatusFileSize
new1.53 KB

the same patch in diff -u format

owen barton’s picture

I think checking for "dumb" in addition is a good approach (I can confirm that this is what you get with cron on some systems, whilst others leave $TERM unset), but the logic doesn't look quite right to me:

+if [ -z $COLUMNS ] && [ "$TERM" != dumb ]; then

Shouldn't this check be something like: if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != "dumb" ]?

-  $nocolor = (drush_get_option(array('nocolor'), FALSE) || !getenv('TERM'));
+  $nocolor = (drush_get_option(array('nocolor'), FALSE) || getenv('TERM') != "dumb");

Same logic issue here.

I think it makes more sense to keep the "terminal environment logic" all together in the drush script wrapper. This means that users of other platforms/shells (e.g. Windows, other *nix, tcsh etc etc) can write their own native wrappers without bumping into terminal environment logic in the main php code. Hence, I would suggest that we drop the whole getenv here, and alter the existing color disabling logic to also detect a $TERM = "dumb".

owen barton’s picture

Status: Active » Needs work
greg.1.anderson’s picture

Okay, I've just skimmed this and the other issue, but I think I'm convinced. Will return to this later.

greg.1.anderson’s picture

Edit: I was insane when I wrote the comments here, so I've deleted them. :p

bibo’s picture

Subscribing.

I just noticed that my new drush crontab (which is run every minute), fills the mailbox with errors. I actually tried to fix it in crontab, like this guy:
http://www.practicalweb.co.uk/blog/10/02/18/drush-tput-no-value-term-and...

It didnt work for me though. It's definitely not critical, but annoying. 'm just waiting until this is fixed in drush.

Thanks for the awesomeness of drush btw! Makes my life so much easier :)

patrick2000’s picture

In reply to comment #11 by owen barton:

Yes, you ar right of course! Fixed that.

(And forget what I originally said in this comment, please. Must have been infected with insanity. Sorry.)

patrick2000’s picture

StatusFileSize
new1.56 KB
fl3a’s picture

Detected the same behaviour in Drush v.3.3.

greg.1.anderson’s picture

Status: Needs work » Needs review
StatusFileSize
new833 bytes

First, sorry for #8 -- these two issues are unrelated, except for both relating to the tput command. I re-opened #784342: Drush should't use colors if there is no terminal attached to discuss the -t vs --nocolor issue there.

Regarding this issue, it seems that the only thing that we want to fix here is to suppress the message that tput prints to stderr when there is no terminal. I don't like testing for "dumb"; I don't know that $TERM might be "mudo" or "物の言えない" or something else. I know that drush does not need to support every language and every distro, but if there's an alternative that is distro-agnostic, then we should use it.

The enclosed patch simply suppresses everything that tput writes to stderr. This should not interfere with any correct value of TERM, and calling tput should not cause any adverse affects (other than the msg to stderr) when it is called with a "missing" value for TERM. In short, tput is better than drush at detecting whether or not the value of TERM is meaningful.

The TERM tests in environment.inc are not necessary, as stderr is already redirected to stdout there, and the is_numeric test prevents undesirable outcomes when the stderr message is interpreted as a column count.

This seems to clear everything up for me; does anyone know of other cases I missed, where calling tput still causes problems with a missing TERM?

patrick2000’s picture

StatusFileSize
new968 bytes

I am fine with greg's patch. It's simple and fixes the issue.

The fact that COLUMNS could be exported while containing just an empty string (in case "tput columns" fails because TERM=dumb) could maybe be ironed out... ?

moshe weitzman’s picture

Assigned: Unassigned » greg.1.anderson
Status: Needs review » Reviewed & tested by the community

Greg should commit this when he is satisfied.

greg.1.anderson’s picture

Committed.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed
kotnik’s picture

Status: Fixed » Needs work

Sorry, but this is not fixed. Both Ubuntu and Debian (dash and bash) default to 80. For example:

$ echo $(tput cols 2>/dev/null)
80
$ echo $(tput cols)
141

I'll check later what's going on.

kotnik’s picture

Ok, got it now.

Since both stderr (2>/dev/null) and stdout (implicitly via $()) are redirected, tput gets confused and doesn't know for what terminal do we want info for, and returns it's default, hence 80. And currently it will always return 80, regardless of the terminal size.

So, the best approach would be to check for $TERM: if there is no $TERM, then COLUMNS get to be 80. Otherwise, let tput figure out what to do (ie. read termcap file and give us result).

Will provide a patch.

greg.1.anderson’s picture

See #7 & c.; sometimes $TERM is "dumb". Sorry that I tested on an 80-column terminal and didn't notice that it was still broken.

kotnik’s picture

Status: Needs work » Needs review
StatusFileSize
new422 bytes

Term being dumb, doesn't confuse tput

$ export TERM=dumb; echo $(tput cols)
141

Dumb is defined (/lib/terminfo/d/dumb) and tput can handle it. Here's the patch that fixes this.

greg.1.anderson’s picture

Status: Needs review » Needs work

Per #7, your test is not adequate for the situation where TERM is not set.

Try this:

echo $TERM
unset TERM
bash
echo $TERM
tput cols

On Debian (Ubuntu), this prints:

xterm
dumb
tput: No value for $TERM and no -T specified

Other distros might print different values, but the fact remains that there are some instances where $TERM is non-empty, and tput cols prints an error to stderr. I'm a bit at a loss on how to deal with this; if we redirect stderr to /dev/null or to stdout, then tput cols returns the wrong value when $TERM is set. If we don't redirect stderr, then we get an undesirable message.

I can think of only two solutions, neither of which make me terribly happy.

  1. special checking for 'dumb', per #17
  2. call $(tput cols 2>/dev/null), and if the result is non-empty, call $(tput cols) again to get the correct value for COLUMNS

#1 is subject to failure if 'dumb' is ever localized (and frankly I don't know if it is or isn't)
#2 is a little inelegant, as it involves multiple calls to tput

Pick your ugly. I think I prefer #2, but I'm ready to settle on either one and just move on.

kotnik’s picture

I guess you're right with this approach. I'll provide a patch.

owen barton’s picture

I have done some Googling and I am pretty sure TERM=dumb is a standard terminal type (like xterm), not a language or (very) distro specific convention. Between this and checking for an unset TERM, I think we should be covered. Hence, I would lean towards #1, unless we have an actual example of a "width-less" terminal other than NULL or "dumb".

greg.1.anderson’s picture

I can go with that. Sorry for #19.

Looks like we can basically go with #17, although this does bring up the question of whether exec('tput colors 2>&1'); returns the correct value, or the default value for colors per #25. Might want to avoid setting COLUMNS unless necessary per #20.

Since this issue has turned out to be so convoluted, a goodly amount of commenting would be nice too.

markus_petrux’s picture

subscribe

greg.1.anderson’s picture

Status: Needs work » Needs review
StatusFileSize
new2.25 KB

I just tried to make my terminal wider to see more info, and got annoyed by my bug in #19. Here's a patch that fixes it, as we discussed above.

daniels____’s picture

Patch tested and seems that works fine.

moshe weitzman’s picture

Committed. Thanks.

moshe weitzman’s picture

Status: Needs review » Fixed
patrick2000’s picture

Thank you everybody for fixing this! Perfect.

Cheers

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.