문제

I am using the following command

print Popen(['ls'], stdout=PIPE).communicate()[0]

which outputs

b'pi\ntem\ntemp\n'

P.S. I am using raspberry pi which has Raspbian Linux

도움이 되었습니까?

해결책

You're using Python 3, which differentiates between strings and byte arrays. You need to decode the byte array returned by the communicate() method:

print(Popen(['ls'], stdout=PIPE).communicate()[0].decode('utf-8'))

Some useful information can be found here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top