views:

16

answers:

1
>>> a = os.popen('chcp 65001')
>>> a.read()
'Active code page: 65001\n'
>>> a.close()
>>> a = os.popen('chcp')
>>> a.read()
'Active code page: 437\n'
>>> a.close()

After I set the codepage to 65001, the next time i call chcp it should say the active codepage is 65001, not 437. I tried this in windows command prompt and it worked. Why doesn't it work through python code?

+1  A: 

The reason is that every time you call os.popen you are spawning a new process. Try opening up two cmd.exe sessions and running chcp 65001 in one and chcp in the other -- that's what you are doing here in your Python code.

One thing to note: all of the [popen*()][1] calls are depreciated as of Python 2.6. The new module to use is the subprocess module.

Sean Vieira