egencache,emirrordist: export NOCOLOR if no tty
diff --git a/bin/egencache b/bin/egencache
index cbc4b28..59d5c3b 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -845,17 +845,18 @@
 
 def egencache_main(args):
 
+	# The calling environment is ignored, so the program is
+	# completely controlled by commandline arguments.
+	env = {}
+
 	if not sys.stdout.isatty():
 		portage.output.nocolor()
+		env['NOCOLOR'] = 'true'
 
 	parser, options, atoms = parse_args(args)
 
 	config_root = options.config_root
 
-	# The calling environment is ignored, so the program is
-	# completely controlled by commandline arguments.
-	env = {}
-
 	if options.repo is None:
 		env['PORTDIR_OVERLAY'] = ''
 	elif options.portdir_overlay:
diff --git a/pym/portage/_emirrordist/main.py b/pym/portage/_emirrordist/main.py
index b94bff0..e19f4aa 100644
--- a/pym/portage/_emirrordist/main.py
+++ b/pym/portage/_emirrordist/main.py
@@ -224,8 +224,13 @@
 
 def emirrordist_main(args):
 
+	# The calling environment is ignored, so the program is
+	# completely controlled by commandline arguments.
+	env = {}
+
 	if not sys.stdout.isatty():
 		portage.output.nocolor()
+		env['NOCOLOR'] = 'true'
 
 	parser, options, args = parse_args(args)
 
@@ -235,10 +240,6 @@
 
 	config_root = options.config_root
 
-	# The calling environment is ignored, so the program is
-	# completely controlled by commandline arguments.
-	env = {}
-
 	if options.repo is None:
 		env['PORTDIR_OVERLAY'] = ''
 	elif options.portdir_overlay: