utf 8 - python print statement with utf-8 and nohup -


i have python code prints log messages. when run @ command line, fine utf-8. log messages contain special characters print out fine. however, when run in background under nohup, barfs on utf-8 characters.

nohup python2.7 myprogram.py & 

the error see usual "try encode utf in ascii" error:

unicodeencodeerror: 'ascii' codec can't encode character u'\u2013' in position 71: ordinal not in range(128)

i assume because nohup signals python doesn't have normal terminal, defaults ascii. there way either tell nohup run utf-8 enabled or set utf-8 characters won't cause crash when running under nohup in background?

use pythonioencoding:

export pythonioencoding=utf-8 nohup python2.7 myprogram.py & 

for example, if

myprogram.py:

unicode_obj=u'\n{infinity}' print(unicode_obj)     

then running

nohup python2.7 myprogram.py > /tmp/test & 

produces

/tmp/test:

unicodeencodeerror: 'ascii' codec can't encode character u'\u221e' in position 0: ordinal not in range(128) 

while

export pythonioencoding=utf-8 nohup python2.7 myprogram.py > /tmp/test & 

produces

/tmp/test:


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -