Execute complex shell commands within python and obtain the output.
Hongyi Zhao
hongyi.zhao at gmail.com
Tue Sep 3 09:33:27 EDT 2019
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
More information about the Python-list
mailing list