How to execute windows commands (ipconfig,netstat) with specific locale/codepage using python
I want to parse to output of windows commands such as ipconfig
, netstat
, tasklist
etc. using python.
But certain part (Fixed) of output of these commands is returned based on current locale/codepage.
E.g. in ipconfig
output
the string IP Address..........:123.23.242.12
will be in chinese IP 地址 ..........:123.23.242.12
or in other language depending on codepage.
Is there any way of executing commands such as os.popen("ipconfig")
with specific locale/codepage setting.
I tried usin开发者_开发知识库g locale module:
locale.setlocale(locale.LC_ALL,"american_united states")
locale.getlocale()
returns"English_United States.1252"
butos.system("chcp")
still returns old codepage:936
andos.popen("ifconfig")
returns strings in chinese.os.system("chcp 65001")
nowos.popen("ifconfig")
returns english strings but it clears all the previous output from console(may be it opens new console) which is not acceptable.
Is there any way of executing commands such as os.popen("ipconfig")
with specific locale/codepage setting? Any help is appreciated.
精彩评论