uniicode and executing a process with subprocess.call, or os.system

Rick King rickbking at comcast.net
Sat Jul 18 18:30:52 EDT 2009


Hello,
I want to copy files using subprocess.call or os.system where the file 
names are non-ascii, e.g. Serbian(latin), c's and s's with hacheks,etc. 
Windows stores all the file names in unicode so they are displayed ok in 
explorer, and I can read them into my program with listdir(u'.'), etc. 
and work with the names in the program.

os.rename()

can be used to rename such files successfully.

But I want to be able to copy files using:

cmdstr = u'copy' +u' /Y "'+pair[0]+u'" "'+pair[1]+u'"\n'
cmdstr = cmdstr.encode(sys.getfilesystemencoding())
try: retcode = sp.call(cmdstr, shell=True) #SP=SUBPROCESS

but the encoding can't handle all the characters and so the file isn't 
found to be copied. sp.call() returns 1. 'mbcs' encoding doesn't work 
either. 'utf-8' doesn't work.

I am very confused about unicode. Can someone point me in the right 
direction?

windows xp sp2
python 2.6.2 unicode

Thanks!
Rick King
Southfield MI







More information about the Python-list mailing list