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

R

Rick King

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
 
M

Martin v. Löwis

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

Try Python 3.1. This should accept Unicode strings directly for sp.call,
so you wouldn't need to encode first.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top