开发者

How to execute windows commands (ipconfig,netstat) with specific locale/codepage using python

开发者 https://www.devze.com 2023-03-30 18:20 出处:网络
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

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.

  1. I tried usin开发者_开发知识库g locale module: locale.setlocale(locale.LC_ALL,"american_united states") locale.getlocale() returns "English_United States.1252" but os.system("chcp") still returns old codepage: 936 and os.popen("ifconfig") returns strings in chinese.

  2. os.system("chcp 65001") now os.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号