Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU parallel - keep output colored

I'm parallelizing some 0-args commands (scripts/whatever) which have colored outputs, but when parallel prints the output it's colorless (unless I use the -u option, but then it's unordered).

Is there a way to change that?

The line I'm using (illustration):

echo "script1 script2 script3" | tr " " "\n" | parallel -j3 'echo {}":\n\n"; eval {}'

BTW, I'm using a local version of GNU parallel, but it's supposed to be more or less the same.

Thanks

like image 326
elad Avatar asked Oct 18 '22 20:10

elad


1 Answers

The reason is that your commandline tools detect that they are not printing to a terminal (GNU Parallel saves into temporary files before printing them to the terminal). Some tools you can force colors even if the output is to a file:

parallel 'echo {} | grep --color=always o' ::: joe

You can ask GNU Parallel to give the script the tty:

parallel --tty -j+0 'echo {} | grep o' ::: joe

--tty defaults to -j1 so you have to explicitly override that. It also has problem, that GNU Parallel cannot kill the jobs. This will run for 10 sec:

parallel --tty --timeout 5 sleep ::: 10
like image 98
Ole Tange Avatar answered Oct 31 '22 14:10

Ole Tange