I could do some tests on a windows 7 system. The problem is not on the execution of a command but only on the display of UTF-8 characters.
First, it works almost correctly using Python 3.4 : it can display ä without problems. So I assume you are using a 2.x version.
On a 2.x version, it is almost impossible to have proper display of UTF8 strings. If you manage to do it correctly, the driver will complain because the number of characters is different than the number of bytes.
You could find some more references here : Windows cmd encoding change causes Python crash. In particular, the referenced Python bug was still active the 2014-10-02 ...
So what to do ?
The only correct solution in Windows is to use a 8bits only character set. Latin1 (windows cp 1252) should display swedish characters provided you use a Consolas
font. CP850
is normally the OEM raster character set (in western Europe) and works also correctly.
EDIT : concrete how-to
for Python 2.7 :
#first define a unicode string in a portable way
utxt = u"Echo hej v\u00e4rld"
#convert it in ANSI (whatever the current console cp can be)
txt = utxt.encode('cp1252')
os.system('echo ' + txt)
for Python 3.x :
#first define a unicode string in a portable way
utxt = u"Echo hej v\u00e4rld"
os.system('echo ' + txt)
Of course, if you have the # -*- coding: utf-8 -*-
line, you can safely write värld
instead of v\u00e4rld
EDIT (4):
eryksun's comment is the proper explaination to what happens. Python 2.7 uses CreateProcessA
meaning it wants the input of the command in what Windows uses for its ANSI code page and not the OEM code page. So for a system using Windows 1252 as its ANSI code page, you must convert the command to cp1252
.
Latin1 (or iso-8859-1), Latin9 (iso-8859-15) and windows 1252 are almost the same character set ... but the €
sign is the difference between them ! And if you want it under windows you must use the cp1252
variant