popen and unicode

Stuart McGraw smcg4191 at frii.RemoveThisToReply.com
Tue May 25 13:30:57 EDT 2004


When I run (Python 2.3.3) this script on a MS Windows 2000 machine:

    import os
    print "1st popen..."
    f = os.popen ("echo " + u"\u0054\u0045\u0053\u0054.txt")
    print f.read ()
    print "2nd popen..."
    f = os.popen ("echo " + u"\u5927\u7530\u8061\u7f8e.txt")
    print f.read ()

I get this:

    1st popen...
    TEST.txt

    2nd popen...
    Traceback (most recent call last):
      File "test.py", line 6, in ?
        f = os.popen ("echo " + u"\u5927\u7530\u8061\u7f8e.txt")
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-8: ordinal not in range(128)

Does os.popen() work with unicode strings containing characters outside 
the ASCII range?  (I think I answered my own question, above.)

How can I call popen to process non-ascii filenames on a Windows box? 
Is there anything else I could use (e.g. spawn) that will work with unicode
filnames?





More information about the Python-list mailing list