bash - Python stdout influenced by TERM setting -


for small project decided give python go first time. got code work fine when handling output of python script noticed strange behavior.

it seems terminal setting used influences python's print function outputs.

here's simplified version of code:

#!/usr/bin/python print 'one two' 

normal output expect:

~/$test.py 1 2 ~/$ 

but if try , bash read output, fails. , here's how replicate problem:

~/$ set -x ~/$ ./test.py | while read v1 v2; echo $v1; echo $v2; grep -c "$v1" /myfile; done + ./test.py + read v1 v2 + echo 'one' 1 + echo 2 two + grep -c 'one' /etc/passwd grep: unmatched [ or [^ + read v1 v2 ~/$ set +x 

notice single quotes around 'one'? , '[' grep complains about. when redirected output file, , loaded in vi, saw control characters in front of output.

to fix problem, run command this:

~/$ (term=dumb; ./test.py | while read v1 v2; echo $v1; echo $v2; grep -c "$v1" /myfile; done) 

this works fine, i'd know why python decides needs format output terminal. , more importantly, how control behavior?

thanks time.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -