473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

popen and unicode

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?
Jul 18 '05 #1
2 4291
Stuart McGraw:
Does os.popen() work with unicode strings containing characters outside
the ASCII range? (I think I answered my own question, above.)
There is no Unicode support in the current implementation of popen. This
could be added in a similar way to the Unicode file name support but it is
more work than I currently have time for. If you are interested in fixing
this, the code is in dist/src/Modules/posixmodule.c _PyPopenCreateProcess.
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?


You can use ctypes to call the underlying platform APIs.

Neil
Jul 18 '05 #2
Thanks for the info, Neil.

I tried using spawnv too, with slightly different but still
unsuccessful results. With spawn, the spawned program
is receiving unicode characters, but non-ascii range
characters have been converted to unicode "?" before
the spawned program receives them. .

I looked into calling the Windows API using Ctypes but how
to convert a C *File pointer returned by Windows' popen()
to something that Python could use, was not at all clear to
me. I guess it would be fairly simple with a C extension, but
that is a bit beyond me at this point.

So, to my surprise, I conclude that it is not currently feasible
to work with the process stuff and unicode file names on a
Windows machine with Python. I would still love to find out
I am wrong though. And I think this info should be in the
documentation. It would have saved me a couple day's
work.

"Neil Hodgson" <nh******@bigpond.net.au> wrote in message news:X6****************@news-server.bigpond.net.au...
Stuart McGraw:
Does os.popen() work with unicode strings containing characters outside
the ASCII range? (I think I answered my own question, above.)


There is no Unicode support in the current implementation of popen. This
could be added in a similar way to the Unicode file name support but it is
more work than I currently have time for. If you are interested in fixing
this, the code is in dist/src/Modules/posixmodule.c _PyPopenCreateProcess.
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?


You can use ctypes to call the underlying platform APIs.

Neil

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: bastiaannaber | last post by:
I am trying to write a program which uses popen but I have a problem. I want to detect if the program I call with popen has ended. For example: #include <stdio.h> #include <sys/types.h>...
1
by: calmar | last post by:
Hi all, first of all, I have to say I have hardly no knowledge about that issue. on the program there, I have it like that: ,------------------------------------------------------- | obj...
2
by: Maarten van Veen | last post by:
A long story made short, I've build a python/cgi website consisting of two pages. Page1 has a html form in which you can input a series of queries. Then via Popen it starts a pythons search script,...
2
by: Méta-MCI | last post by:
Hi! From long time, I have problems with strings return, in Windows, by subprocess.Popen / stdout.read() Last night, I found, by hazard, than if the second byte equal 0, it's, perhaps, the...
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
3
by: Jesse | last post by:
Hi all, I have a problem using wget and Popen. I hope someone can help. -- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org" and capture all it's...
11
by: John Nagle | last post by:
I passed a dict for the "env" variable to Popen with Unicode strings for the dictionary values. Got: File "D:\Python24\lib\subprocess.py", line 706, in _execute_child TypeError: environment...
25
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
1
by: Mark Shewfelt | last post by:
Hello, I am attempting to use Popen() in a Windows service. I have a small Win32 .exe that I normally run through the os.popen2() function. I've written a class to work with the input and output...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.