git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Execute complex shell commands within python and obtain the output.


On Tue, 03 Sep 2019 17:27:59 +1000, Cameron Simpson wrote:

> It was merely that it is hardwired in your code (and you need to wire in
> something). Just keep in mind that _if_ this script runs in a non-utf8
> environment the decoding may be wrong. Unlikely to actually happen
> though.

Thanks, fixed with the following:

import subprocess,locale

a=locale.getdefaultlocale()
cmd=...
ps=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE) 
output =ps.communicate()[0].decode(a[1])

Regards