How to replace stdout\ nin subproccess with <br>

I want to replace n in subproccess"s stout with
. I tried the following, but it didn"t work, using python3

a=subproccess.Popen("ls -al",stdout=subproccess.PIPE,shell=Ture)

I used the following code first, but there was an error "str"does not support the buffer interface

.
b=a.stdout.read().replace("\n","<br>") 

then I tried the following command again, and there was no error, but the replacement was not successful

b=str(a.stdout.read()).replace("\n","<br>") 
Mar.29,2021

your code is wrong from beginning to end. Can you organize the code when you ask questions? The version of python used is also not specified

I assume you are using python2, and you want to read standard output from subprocess. The correct way to write it is:

a = subprocess.Popen('ls -l', shell=True, stdout=subprocess.PIPE)
b = a.stdout.read().replace('\n', '<br>')

if python3,a.stdout.read () gets bytes, so you can:

b = a.stdout.read().decode().replace('\n', '<br>')
Menu