1

I have a bash script to run python script with arguments and it's working perfectly in terminal but when I run it in background mode using php, it gives me encoding error. actually script doesn't have any errors.

The command in terminal is just sudo bash total_report.sh

Background mode in php script: shell_exec("sudo bash total_report.sh > /dev/null 2>/dev/null &") I know this is locale issue but please teach me how to solve this problem.

 'ascii' codec can't encode character '\xae' in position 59: ordinal not...
Alex
  • 1,148
  • 8
  • 30
  • why add python tag here ? maybe [this](https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20) can help you – sahasrara62 Nov 18 '19 at 22:36
  • That is the ® character, FWIW – JacobIRR Nov 18 '19 at 22:36
  • Thanks @temmo. I've already checked but I don't want to change python code since it's working perfectly without any issues in terminal. but not working when I run it in background via PHP – Alex Nov 18 '19 at 22:39
  • @AlexandrBiship since you are doing it with web you need to add instructions format ie utf8 acceptable by terminal – sahasrara62 Nov 19 '19 at 06:10

1 Answers1

2

I solved this issue by changing global locale of OS (Ubuntu in my case).

$ locale

enter image description here

In my case, LC_ALL was empty as default. run this command to set it up. (this is a temporary resolution. this value will be go away after OS restart)

$ export LC_ALL=en_US.UTF-8

You can also set it in /etc/default/locale. I actually don't know exact reason so any comments would help me and everybody.

Alex
  • 1,148
  • 8
  • 30