Windows, subprocess.Popen & encodage

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 solution.
With a code like this:

     p=subprocess.Popen(u850("cmd /u/c ....
     tdata=p.stdout.read()
     if ord(tdata[1])==0:
         data=tdata.decode('utf-16')
     else:
         data=tdata.decode('cp850')

Diffrents scripts seem run OK. I had try with:
   - common dir
   - dir on unicode-named-files
   - ping
   - various commands


But, I don't found anything, in any documentations, on this.



Sombody can confirm?   Am I misled?  Am I right?



* sorry for my bad english*


@-salutations

Michel Claveau

0
5/8/2007 6:43:04 AM
comp.lang.python 74898 articles. 0 followers. Post Follow

2 Replies
165 Views

Similar Articles

[PageSpeed] 24
> But, I don't found anything, in any documentations, on this.
> 
> Sombody can confirm?   Am I misled?  Am I right?

You are right, and you are misled. The encoding of the data
that you get from Popen.read is not under the control of Python:
i.e. not only you don't know, but Python doesn't know, either.
The operating system simply has no mechanism of indicating
what encoding is used on a pipe.

So different processes may chose different encodings. Some
may produce UTF-16, others may produce CP-850, yet others
UTF-8, and so on. There really is no way to tell other than
reading the documentation *of the program you run*, and,
failing that, reading the source code of the program you
run.

On Windows, many programs will indeed use one of the
two system code pages, or UTF-16. It's true that
UTF-16 can be quite reliably detected by looking at the
first two bytes. However, the two system code pages
(OEM CP and ANSI CP) are not so easy to tell apart.

Regards,
Martin
0
ISO
5/8/2007 7:15:49 AM
Thank you.






-- 
@-salutations

Michel Claveau


0
XX.XmcX (47)
5/8/2007 7:34:17 AM
Reply:
Similar Artilces:

pass an object to a new window
On IE there is a way to open a window from one page and pass an object to it, when you use showModalDialog. Is there a way to do the same on NS/Mozilla/FireFox? On IE: window.showModalDialog(URL, FreeArgument, Ornaments); FreeArgument. You can use this optional parameter to pass a value of any type to the open dialog box. You can pass a scalar, a string, an array of values, an object, etc. You access this value in the new window by referring to the dialogArguments property of the new window object. Thanks In article <75467213.0502161408.325465ce@posting.google.com>, mitch.tzonev@sr...

segfaulting in IO.popen()
--=-4SIfvHv0YxMfkVBn05d3 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, I'm having a problem w/ mod_xmlrpc segfaulting inside a call to IO.popen. The code snippet that's being run is: cmd =3D 'sudo ' + PRIV + ' /usr/bin/apt-get -u --trivial-only dist- upgrade' skip =3D 2 f =3D IO.popen(cmd) output =3D f.readlines Here's the backtrace: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1079499040 (LWP 14934)] 0x4063931e in st_lookup (table=3D0x0, key=3D321, value=3D0xbfff92b8) at st.c:258 258 hash_val ...

Calling data windows from data windows?
Hi to all! Please, let me clear out some basic things about calling windows: - a DataWindow, named BrowseDates i have a button with a method for calling a DataDialog, named AddingAccounts, which looks like: METHOD DNewAccountButton() CLASS BrowseDates LOCAL oAddingAccounts AS AddingAccounts oAddingAccounts := AddingAccounts{} oAddingAccounts:Setup(SELF:Server:TableDate) oAddingAccounts:Show() SELF:Owner:AddChildWindow( oAddingAccounts ) RETURN SELF - This far, everything is ok, and a new windows shows up. But, on a dataDialog I have a button for calling another dataWindow, c...

partial expect for windows
I understand that the main problem with new versions os expect for windows is with the spawn command. Has anyone got working code (eg tcl source) that implmements expect in newer tcl versions on windows WITHOUT spawn (ie using an already open channel, such as a serial port)? thanks ...

=?windows-1252?Q?www=2Eelectronics=2Dmac=2Dsony=2Ecom_Toshiba_Satellite_A215=2D?= =?windows-1252?Q?S6804_15=2E4=22_Laptop_=28AMD_Turion_64_X_2_Dual_Core_TL=2D60_Process?= =?windows-1252?Q?or=2C_
http://www.electronics-mac-sony.com Contact us : 7*24 hour On-line service: MSN/Email:electronics-2008-china@hotmail.com Our website:http://www.electronics-mac-sony.com/goods.php?id=3D712 Product Features and Technical Details Product Features * Bright 15.4-inch LCD stylishly accented with an onyx blue metallic LCD cover and integrated Webcam * 2.0 GHz AMD Turion 64 X2 TL-60 processor, 250 GB hard drive, 2 GB RAM (4 GB max), dual-layer DVD writer with LabelFlash printing * 54g Atheros Wi-Fi (802.11b/g); 10/100 Ethernet; ATI Radeon X1200 graphics card with up to 319 MB of shared m...

Mobile Me / Windows Live
I am not a Windows type of guy and have always hated Hotmail but things seem to be changing with Windows Live: - POP3 access on free account - Nnlimited email storage - Sky Drive with 25 gig of storage free Seems to be something of a threat to Mobile Me. I wonder how apple will respond? In article <0001HW.C5C02DCE0002520CB01AD9AF@europe.newsdemon.com>, Skipper <mail@xxx.co.uk> wrote: > I am not a Windows type of guy and have always hated Hotmail but things seem > to be changing with Windows Live: > - POP3 access on free account > - Nnlimited email storage > -...

Windows XP and Singlelineedits with background
VO 2806 (and also VO 2.5 with XP-Additions) When the XP-Style is enabled and I am using singlelineedits with a background the border is not displayed correctly. When hovering with the mouse over the control the sle is displayed correctly or when disabling/controle the control after setting the background. Does some has an idea what to change apart from calling disable/enable after setting the background? Arne Ortlinghaus ACS Data Systems 2806! Is this the long awaited 30 April release?????? Sorry but can you please retype your message? I am not completely sure ...

window-handlers on windows
hi (this is my first post to this ng; so if it is the wrong ng, please direct me to the one i need...) my problem not necessarily bound to C++ (but could also be C), but since my application is in C++, i post it here. i want to draw from application A into a window that has been created by an application B (in my case: i want to render an openGL-scene into a a browser-window) under linux i can get a handle of type "Window" from the Xserver, into which i can draw (assumed that i have permissions) under windows the only such handle i have found is HWND, which is a pointer to a ...

Showing all tooltips in a window
It would be a nice affect for beginners or demos that the tooltips of all controls in a window are displayed (or maybe one after another). Is there a possibility to do this? Arne Ortlinghaus ACS Data Systems Arne, Actually no, I don't think so. Tool tips are invariably too short and controls too close together for something like this. And it would be seen as a gimmick and most would want to turn it off very quickly. I think the best thing to do is produce a well documented (including image shots with annotations) help manual and link it in solidly to your windo...

Windows 2000 over Windows ME install?
Greetings, I have a computer which has Windows ME currently installed on it. I have a license of Windows 2000 sitting around doing nothing, and I'd like to install the Win2k over ontop of the WinME. Will I have to wipe out the WinME completely and start from scratch on the Win2k install, or can I safely install the Win2k over the top of WinME? Thanks in advance, -Geoff I think Win2k can be upgraded only from WinNT. You will have to do a clean install. Geoff Cashman wrote: > > Greetings, > > I have a computer which has Windows ME currently instal...

Remote printing OS to Windows interface
Hi, I've just installed a remote printer in OS507 - the printer is on a Windows box, and unix can lp to it OK. There doesn't seem to be an interface file in /var/spool/lp/admins/lp/interfaces for this printer. Is it somewhere different or do we get no control over the print job this way? Relevant info - I had to uninstall cups before installing remote printing, and I haven't reinstalled. I've never used cups before - will it help? - I use a simple tailored interface file which among other things sends some pcl to the laser to change the font. thanks in advance -Rob robat...

=?windows-1252?Q?Special_Track_=93Computational_Bioimaging_and_Visual?= =?windows-1252?Q?ization=94_within_the_ISVC08_USA_=2D_Announce_=26_Call_for_Papers?=
----------------------------------------------------------------------------= ------------------------------------------------------------- (Apologies for cross-posting) Special Track =93Computational Bioimaging and Visualization=94 International Symposium on Visual Computing (ISVC08) Las Vegas, Nevada, USA, December 1-3, 2008 http://www.isvc.net We would appreciate if you could distribute this information by your colleagues and co-workers. ----------------------------------------------------------------------------= ------------------------------------------------------------- Dear Colle...

3dmax like paned windows
Does anyone know how to create pure tcl paned-widown like 3d Max which has a handle allows you to grid the 4 windows at one instance. In panedWindow you can either seperate vertical or horizontal. 3d Max however allows you to scale the window in both direction at the same time. If not one available, can anyone layout what kind of knowledge I NEED to know in order to create one. Thanks, Alex tak wrote: > Does anyone know how to create pure tcl paned-widown like 3d Max which > has a handle allows you to grid the 4 windows at one instance. > > In panedWindow you can either seper...

=?windows-1256?B?2sfM4SDk5NTRIMrdx9Xt4SDH4craz+3hIMfh5g==?= =?windows-1256?B?0sfR7SDH4czP7c8gx+HQ7SDT7crjIMfhx9rhx+Qg2uQ=?= =?windows-1256?B?yQ==?=
2sfM4SDk5NTRIMrdx9Xt4SDH4craz+3hIMfh5tLH0e0gx+HMz+3PIMfh0O0g0+3K4yDH4cfa4cfk INrkyQoKaHR0cDovL25hdGlndGFzN2FiLmJsb2dzcG90LmNvbS8yMDEzLzA0L2Jsb2ctcG9zdF83 NDM1Lmh0bWw= ...

Setting the window size
Dear All, How do I set the size of the window that is showing the database forms? can't find any helps on it. John Fox On Apr 19, 6:33 am, John Fox <altab...@bham.ac.uk> wrote: > Dear All, > > How do I set the size of the window that is showing the database forms? > > can't find any helps on it. > > John Fox Are you talking about at design time? All you have to do is make sure the window is not maximized so you can view its normal size, then click and drag the edges of the window to resize. If you save the form after changing the size, this will stic...

Root Window & Windows within Windows
Even (on 98) if you replace the shell explorer.exe you are left with the root window. Explorer.exe does a good job of adding content to the root window. It places icons on your desktop and gives you a task bar. The only ability I am aware of that programmers have to add content to the root window (aside from replacing explorer.exe), is with Active Desktop. I feel that active desktop should be a program we can write ourselves. We should be able to write our own programs that are drawn directly to the root window, just like active desktop windows are. Even when you replace ...

Filer like windows
I intend to write a program that can keep a number of images and draw files in memory at the same time. The user should be able to access every file individually. What I plan to do is a window that contains every available file like in a filer window. I would also like to have the option to show large icons/small icons/full info and maybe later even a thumbnail of the images. May question is: Is there something like a toolbox module which makes it easy to achieve a filer like display or do I have to go the long way and implement everything by myself? If there is something I can use, it shou...

Overplot cgplots in graphics window
Hello, I have several data sets of trajectories that I want to plot together in on= e graphics window. I am able to rerun the code and have it overplot in the = display window but I'm not able to save that. I've tried creating a resizab= le graphics window but because the cgplots commands are in a loop, IDL cont= inually displays new graphics windows and then crashes. Is there a way that= I can rerun my code with a new data set each time and overplot on the same= map and then save the graphic without having to just copy and paste my cod= e 3x in the same program? I've i...

anybody send me a copy of "netpbm-10.6-1-bin.zip" on GNUWIN32 for my windows system?
Dear all, I want to install Latex2html, but today the "netpbm-10.6-1-bin.zip" could not be download from sourceforge website. I don't know why... I tried many times but failed. Without that file the Latex2html does not install. Can anybody send me a copy of that file? Thanks a lot, -Walala > I want to install Latex2html, but today the "netpbm-10.6-1-bin.zip" could > not be download from sourceforge website. I don't know why... I tried many > times but failed. Try to use http://prdownloads.sourceforge.net/gnuwin32/netpbm-10.6-bin.zip?download inst...

IE shows site directory after onclick window.open
Is this how it's done? IE 6.0 after opening bigger.html in a new page, then shows the site directory contens in the main window. ?! The popup page bigger.html shows a larger pic of a product. In my main page I define a function 'open_popup' and call it for all the product images, in case the customer wants a bigger pictures. function open_popup(page) { window.open(page,'Larger_Image','width=400,height=300,resizable=yes,toolbar=no,statusbar=no,scrollbars=no'); } <body> <a href="" onclick="return open_popup('bigger.html')"> ...

perl2exe on Windows and BrowseEntery: not running
By adding and removing modules, I finally narrowed this down to Tk::BrowseEntery. For the first time in a while, I couldnt find the answer in Google. Any help will be appreciated. perl2exe compiles the script (http://www.ie.u-ryukyu.ac.jp/~kono/lecture/software/s07/demos/widtrib/browseentry2.pl) fine but then when I try to run the .exe, I get this: couldn't read bitmap file "": No such file or directoryerror reading bitmap fil "" at PERL2EXE_STORAGE/Tk/Widget.pm line 205. at PERL2EXE_STORAGE/Tk/Widget.pm line 203 This exe file was created with the evalu...

Tater Tot blames users for Windows 7 problems
Tater Tot was stupid enough to say:: > I guess the "discount" meant they had to remove a way to make sure you > got the right OS version... Nobody blamed the students. It was noted they were confused but nothing in the article says this was their weakness. On Nov 8, 12:00=A0am, Anne Onime <anonym...@rip.ax.lt> wrote: > Tater Tot was stupid enough to say:: > > > I guess the "discount" meant they had to remove a way to make sure you > > got the right OS version... > > Nobody blamed the students. So why are Reuters, C...

MATLAB windowing
I have maximized my main window and i want the user to cannot move it! How can i do that?! Thanks ...

How to alter Aeskulap for Windows
I'm using Aeskulap's for windows version 0.2.1. It currently uses Patient Root information model when Querying. I'd like to change it to use Study Root to overcome a compatibility issues I'm encountering with an SCP. I've tried going though the source code but have been unsuccessful finding where to go to adjust this value. Any guidance would be greatly appreciated. ...

Tables in Composition Window
I like to be able to paste Web pages into E-mail messages. In Thunderbird and M$ Outlook, much of the formatting, including tables, is transferred. In Eudora, only the text formatting and images are accepted. There are no tables. And there doesn't seem to be any way to insert a table when composing from scratch, even in Eudora 7. Is there something wrong with my setup? Or does Eudora just not support tables? I am interested because I like Eudora's ability to edit or annotate received messages, which Thunderbird doesn't have. And I would prefer to avoid Outloo...