f



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 76994 articles. 3 followers. Post Follow

2 Replies
399 Views

Similar Articles

[PageSpeed] 9

> 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:

subprocess.Popen on Windows
playing with subprocess.Popen on Windows I stumbled into the following problem: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) IDLE 1.1.3 >>> import subprocess >>> p1=subprocess.Popen("c:\\asd.bat") #works OK >>> p2=subprocess.Popen("c:\\asd.bat",stdout=subprocess.PIPE) Traceback (most recent call last): File "<pyshell#2>", line 1, in -toplevel- p2=subprocess.Popen("c:\\asd.bat",stdout=subprocess.PIPE) File "C:\Python24\lib\subprocess.py", line 533, in __init__ (p2cread, p2cwrite, File "C:\Pytho...

A Lange & Sohne Lange 1 Watches: Quality A Lange & Sohne Discount Watches
A Lange & Sohne Lange 1 Watches: Quality A Lange & Sohne Discount Watches Quality A Lange & Sohne Lange 1 Watches http://a-lange-sohne-watches.pxhelp.com/a-lange-sohne-lange-1.html Thank you for choosing http://www.pxhelp.com/ Discount A Lange & Sohne Watches http://a-lange-sohne-watches.pxhelp.com/ We guarantee our A Lange & Sohne Lange 1 Watches and A Lange & Sohne Lange 1 Luxury Watches aren't just a simple imitation. We use the same fine materials and technology that the original does. Each A Lange & Sohne Lange 1 Watch produced is examined carefully by ...

A Lange & Sohne Grand Lange 1 Watches: Quality A Lange & Sohne Discount Watches
A Lange & Sohne Grand Lange 1 Watches: Quality A Lange & Sohne Discount Watches Quality A Lange & Sohne Grand Lange 1 Watches http://a-lange-sohne-watches.pxhelp.com/a-lange-sohne-grand-lange-1.html Thank you for choosing http://www.pxhelp.com/ Discount A Lange & Sohne Watches http://a-lange-sohne-watches.pxhelp.com/ We guarantee our A Lange & Sohne Grand Lange 1 Watches and A Lange & Sohne Grand Lange 1 Luxury Watches aren't just a simple imitation. We use the same fine materials and technology that the original does. Each A Lange & Sohne Grand Lange 1 Watc...

subprocess.Popen under windows 7
Hello, i have something like this under windows 7: print("try command...") arglist = [PATH_TO_7ZIP,"a", "-sfx", archive_name, "*", "-r", "-p",PASSWORD] p = subprocess.Popen(args=arglist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=srcdir) output, error = p.communicate() if output: print output print ("Eyerthing is good") press_any_key_to_continue() The script works, but there is a little problem. When I double-click the python file, then the command line will open and the s...

subprocess.Popen on Windows #2
I am trying to use subprocess - it basically works but. command = 'ping ' + '-n '+ str(count) + ' -l ' + str(size) + ' ' + str(node) print command p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) pout = p.stdout.read() This works for me but I see the Windows command window, is there a way to call subprocess without a command window showing? I am trying to replace: fdout, fdin = popen2.popen4('ping...

Re: &&&&&&
Talbot, Its basic macro aper math. With each pass of the macro processor it reduces && to &. in yoru case: %put &&mlv&mlin. = &&&&&&mlv&mlin. ; 1st pass: &mlv5 = &&&mlv5 2nd Pass: Daisy = &Daisy 3rd Pass : Daisy = Yellow Toby Dunn From: Talbot Michael Katz <topkatz@MSN.COM> Reply-To: Talbot Michael Katz <topkatz@MSN.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: &&&&&& Date: Thu, 9 Jun 2005 13:38:44 -0400 Received: from malibu.cc.uga.edu ([128.192.1.103]) by MC8-F21.hotmail...

Uneeded files pt.2: Windows & Windows/System filenames & function list?
I'm just looking thru these dirs and wondering what alot of this crap is. Just by the look of them, alot look like they're one use stuff that isn't needed after install, or at least I don't need. Is there anywhere I can find a list of what's what? This old system needs every byte it's got :) If not, specifically I was wondering what setupslt.exe does. -- _____________________________________________________ For email response, or CC, please mailto:see.my.sig.4.addr(at)bigfoot.com. Yeah, it's really a real address :) ...

A Lange & Sohne Watches: Discount A Lange & Sohne Watch High Quality Watches
A Lange & Sohne Watches: Discount A Lange & Sohne Watch High Quality Watches WelCome to Watches http://www.pxhelp.com/ Discount A Lange & Sohne Watches http://a-lange-sohne-watches.pxhelp.com/ A Lange & Sohne is the top famous watch brand in the world. The style of this watch is elegant in craft and fashion. It is graceful and noble. The perfect union of technology and craft, the guarantee of A Lange & Sohne's brand that is similar to the classical graceful design surmounts the space and time. It unfolds the true macroscopic field of vision and the aesthetic standard...

Re: &&&&&& #2
Alan, I disagree with that statement. I think the best solution would be to build the dang thing the way he want with less macros. By sending your code out then back in is in MO to much hassel for too little. the whole thingy could be done like this: data one ; flower = 'Daisy' ; color = 'Yellow' ; run ; data two ; set one ; call symput ( compress('text'||_n_),compbl(flower||'='||color) ) ; call symput ( 'index' , compress(_n_) ) ; run ; %put &&text&index ; Toby Dunn From: Alan Churchill <SASL001@SAVIAN.NET> Reply-To: A...

Re: &&&&&& #4
> From: Talbot Michael Katz > It requires SIX ampersands to resolve the macro variable > example below: > > data _null_ ; > set DS1 end = last ; > call symput("mlv" || compress(put(_N_,best32.)), mli) > ; > call symput(mli, tdt) ; > if last then do ; > call symput("mlin", compress(put(_N_,best32.))) ; > end ; > run ; > %put &&mlv&mlin. = &&&&&&mlv&mlin. ; > > (So, if there are five observations in the data set, and the > fifth value of > mli is "DAISY" and the fifth value of tdt is "YELLOW" this will print > out "DAISY = YELLOW") > > Why does it take so many ampersands to resolve? Can someone > please explain > this resolution to me so that it gets through my extremely > dense skull? > -- TMK -- > "The Macro Klutz" welcome to the club, Talbot! first let's remember: "Too mini ampersands spoil the &tew.!" you're making an associative array but having a sequential-number macro variable as the index may not be what you want, thus the whine about two many ampersands. you didn't supply test data so I'll just edit this and hope it works: data ds1; infile cards; input @1 mli $char1. @3 tdt $char6. ; cards; a apple b banana c cherry d daisy y yellow ; data _null_ ; set DS1 end = last ; call symput(mli, tdt) ; if last then do ; call symput('Sho...

Re: &&&&&& #6
This is a prime example I use when I discuss what is wrong with the macro language. Yes, you can figure it out but an alternative would be to simply write your data step code out and then bring it back in so you know what is being submitted. data _null_ ; file 'c:\myfile.sas' ; put 'data ...;' ; ...more put statements... run; %include 'c:\myfile.sas' ; Others will argue for SCL or something else. Regardless, this application probably requires a complete rethink if you are using 6 ampersands. Thanks, Alan Savian "Bridging SAS and Microsoft Technologies" -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Talbot Michael Katz Sent: Thursday, June 09, 2005 11:39 AM To: SAS-L@LISTSERV.UGA.EDU Subject: &&&&&& Hi. It requires SIX ampersands to resolve the macro variable example below: data _null_ ; set DS1 end = last ; call symput("mlv" || compress(put(_N_,best32.)), mli) ; call symput(mli, tdt) ; if last then do ; call symput("mlin", compress(put(_N_,best32.))) ; end ; run ; %put &&mlv&mlin. = &&&&&&mlv&mlin. ; (So, if there are five observations in the data set, and the fifth value of mli is "DAISY" and the fifth value of tdt is "YELLOW" this will print out "DAISY = YELLOW") Why does it take so many ampersands to resolve? Can someone please explain this resolutio...

Re: &&&&&& #7
Alan, I seem to have started a hail storm here and I probably should have stated earlier that I don't disagree with SCL or a rework of the code, but rather building and then sending the code out to a temp file and then %including it back in I like not. I have found that while in certain situations this may be the only way to accomplish something easily, it is over used and causes way more headaches than it is worth. As for the rest of your post I am right behind you. Toby Dunn From: Alan Churchill <SASL001@SAVIAN.NET> Reply-To: Alan Churchill <SASL001@SAVIAN.NET> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: &&&&&& Date: Thu, 9 Jun 2005 12:47:23 -0600 MIME-Version: 1.0 Received: from malibu.cc.uga.edu ([128.192.1.103]) by mc7-f17.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Thu, 9 Jun 2005 11:47:32 -0700 Received: from listserv.cc.uga.edu (128.192.1.75) by malibu.cc.uga.edu (LSMTP for Windows NT v1.1b) with SMTP id <1.00FB2139@malibu.cc.uga.edu>; Thu, 9 Jun 2005 14:47:30 -0400 Received: from LISTSERV.UGA.EDU by LISTSERV.UGA.EDU (LISTSERV-TCP/IP release 1.8d) with spool id 2863721 for SAS-L@LISTSERV.UGA.EDU; Thu, 9 Jun 2005 14:47:30 -0400 Received: from IPOfCard1.guest-tek.com ([66.193.160.162]) by listserv.cc.uga.edu (8.12.11/8.12.11) with ESMTP id j59IlULF006633 for <SAS-L@LISTSERV.UGA.EDU>; Thu, 9 Jun 2005 14:47:30 -0400 Received: from alantoshiba (localhost.localdomain [127.0.0.1]) by IPOfCard...

Re: &&&&&& #8
On Thu, 9 Jun 2005 13:38:44 -0400, Talbot Michael Katz <topkatz@MSN.COM> wrote: >Hi. > >It requires SIX ampersands to resolve the macro variable example below: > >data _null_ ; > set DS1 end = last ; > call symput("mlv" || compress(put(_N_,best32.)), mli) > ; > call symput(mli, tdt) ; > if last then do ; > call symput("mlin", compress(put(_N_,best32.))) ; > end ; >run ; >%put &&mlv&mlin. = &&&&&&mlv&mlin. ; > >(So, if there are five observations in the data set, and the fifth va...

Re: &&&&&& #10
Thank you, Toby et al for your answers, opinions, advice, criticism, etc. I almost think I'm beginning to get it. Let me regurgitate this to be sure: Given &&&&&&mlv&mlin., I resolve &mlin. = 5 and reduce the &&&&&& to &&& to get &&&mlv5. Then I resolve &mlv5. = DAISY and reduce the && to & to get &DAISY. Finally I resolve &DAISY. = YELLOW. So, it looks to me like once I reach a stage where I have a string of ampersands followed by a "pure" name (i.e., one with no ampersa...

Re: &&&&&& #3
toby dunn <tobydunn@hotmail.com> replied: > Alan, > > I disagree with that statement. I think the best solution would be to build > the dang thing the way he want with less macros. By sending your code out > then back in is in MO to much hassel for too little. > > the whole thingy could be done like this: > > data one ; > flower = 'Daisy' ; > color = 'Yellow' ; > run ; > > data two ; > set one ; > call symput ( compress('text'||_n_),compbl(flower||'='||color) ) ; > call symput ( 'index' , compre...

Re: &&&&&& #13
Bold=Ian Whitlock Faint Italics=Joe Whitehurst A macro variable can be thought of as a name pointing at a value. A named scl list item can be thought of as a name pointing at a value. So a name can point at a name that can point at a value, etc. So a named scl list item can be thought of as a named scl list item that can point at a named scl list item that can point at a named scl list item that can point at a value which can continue to whatever level of abstraction you wish without ever using any concatenated ampersands. Let's look at the problem by analogy. Suppose you go to a pa...

how to use subprocess.Popen execute "find" in windows
In cmd, I can use find like this. C:\>netstat -an | find "445" TCP 0.0.0.0:445 0.0.0.0:0 LISTENING UDP 0.0.0.0:445 *:* C:\> And os.system is OK. >>> import os >>> os.system('netstat -an | find "445"') TCP 0.0.0.0:445 0.0.0.0:0 LISTENING UDP 0.0.0.0:445 *:* 0 >>> But I don't know how to use subprocess.Popen to do this. from subprocess import Popen, PIPE p1 =3D Popen(['netstat', '-an'], stdout =3D PIPE) p2 =3D Popen(['...

Command prompt not shown when running Python script with subprocess on Windows
I have written a Python script with a wxPython GUI that uses subprocess.Pop= en to open a list of files that the user provides. One of my users would li= ke to be able to run a Python script with my application. The Python script= he is trying to run uses the command line and gets keyboard input from the= user several times. The problem is that if the Python script is run on Windows with subprocess.= Popen, no command prompt is shown (my GUI application is a .pyw file). The = user's script runs silently but then does not quit because it is waiting fo= r input, but there is no way for the input to be given, since there is no c= ommand prompt visible. I think this may be related to the fact that I am calling subprocess.Popen = with shell=3DTrue. I tried calling it with shell=3DFalse (the default), but= then I got an error that the file is not a valid Win32 application. I would appreciate any help with this problem. -- Timothy --047d7b44fc78c67fa704fa5bf227 Content-Type: text/plain; charset=UTF-8 You need to call python.exe path-to-script.py, I think, not just path-to-script.py. See sys.executable (though that depends on if you're a frozen app or not). I can't be sure though because there's no code. Show code when asking questions, it helps frame the discussion and get a better answer ;) On Mon, May 26, 2014 at 5:03 PM, <ps16thypresenceisfullnessofjoy@gmail.com>wrote: > I have written a Python script with a w...

python 2.5 scripting in vim on windows: subprocess problem
Hello! I'm using subprocess.Popen in python script in vim. It called this way: def some_func(): p = subprocess.Popen( command , stdout = subprocess.PIPE, stderr = subprocess.STDOUT) while True: s = p.stdout.readline() if not s: break self.__output( '... %s' % s ) return p.wait() It filters command's output and re-ouputs it in stdout. Being called from console, it works fine. Being called from vim with :python some_func() it says: file "...subprocess.py", line 586 in __init__ .... file "...subprocess.py", line 699, in _get_handles .... file "...subprocess.py", line 744 in _make_inheritable DUPLICATE_SAME_ACCESS WindowsError: [Error 6] Hi! VIM can, also, to be OLE-COM-server. Try with: from win32com.client.dynamic import Dispatch vim = Dispatch('Vim.Application') (+google) @-salutations Michel Claveau ...

Module python-magic on/for Windows
Thank you, again, Michael, for all your help many months ago. I *FINALLY* got a HowTo done up; please see http://wiki.python.org/moin/HowTo/FileMagic I've also emailed Mr. Hupp to see if he'll re-post the SWIG version; he's working on a newer binding (forget... ctypes??) and once that one's working... :) But for now... Cheers, Larry REF: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4c60ec1599056df8/3eff4049a7bfdfc0?hl=en%E3%AD%82a54360c4d26&lnk=gst&q=python-magic#3eff4049a7bfdfc0 Larry Hale wrote: > Thank you, again, Michael, for all ...

Module python-magic on/for Windows
Thank you, again, Michael, for all your help many months ago. I *FINALLY* got a HowTo done up; please see http://wiki.python.org/moin/HowTo/FileMagic I've also emailed Mr. Hupp to see if he'll re-post the SWIG version; he's working on a newer binding (forget... ctypes??) and once that one's working... :) But for now... Cheers, Larry REF: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4c60ec1599056df8/3eff4049a7bfdfc0?hl=en%E3%AD%82a54360c4d26&lnk=gst&q=python-magic#3eff4049a7bfdfc0 ...

'&&&&a'="&&&&a."
I need a data step that is equivalent to data _NULL_; file print; put '&&&&&&a=' "&&&&&&a"; run; Yet the number of & is a variable, I need to write a Macro, so far I got only half of the code('&&&&&&a.='), I don't know how to put the other half ("&&&&&&a.") into Macro Thanks. %Macro R(k); data _NULL_; file print; put %do i= 1 %to &k.; '&' %end; 'a=' ; run; %mend; %R(10); ============================================================================== This communication, together with any attachments hereto or links contained herein, is for the sole use of the intended recipient(s) and may contain information that is confidential or legally protected. If you are not the intended recipient, you are hereby notified that any review, disclosure, copying, dissemination, distribution or use of this communication is STRICTLY PROHIBITED. If you have received this communication in error, please notify the sender immediately by return e-mail message and delete the original and all copies of the communication, along with any attachments hereto or links herein, from your system. ============================================================================== The Travelers e-mail system made this annotation on 06/12/07, 10:22:42. No sure that I follow what you are doing with &&&&&&, but as a su...

tk_getSaveFile & windows & locale
Hi all, on a W2k/German setting, the below script fails with "syntax error in expression "5*100.100": extra tokens at end.... I've read http://wiki.tcl.tk/583 but setting LC_ALL to C does not help. Checking winMain.c I find that LC_ALL is set to C anyway, so I'm kinda puzzled by this error. Any hint how to solve this prob would be very much appreciated. Wolf <script> #!/bin/sh # \ exec wish "$0" -- "$@" puts "v1=[expr 5*100.100]" tk_messageBox -message XXX puts "v2=[expr 5*100.100]" tk_getSaveFile puts "v3=[expr 5*100.100]" exit ...

A && B && ( C && D )
Hi all, I've four conditions expression, A, B, C, and D. Are the following two forms equivalent or not? A && B && ( C && D ) A && B && C && D Regards -- ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. Hongyi Zhao <hongyi.zhao@gmail.com> wrote: >Are the following two forms equivalent or not? > >A && B && ( C && D ) >A && B && C && D Yes. In either case, _all_ variables must be true for the expression to be true. The AND operato...

Web resources about - Windows, subprocess.Popen & encodage - comp.lang.python

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Twitter Engineering: A Storm is coming: more details and plans for release
Thursday, August 4, 2011 A Storm is coming: more details and plans for release We've received a lot of questions about what's going to happen ...

Leather - Wikipedia, the free encyclopedia
Vegetable-tanned leather is tanned using tannin and other ingredients found in vegetable matter, such as tree bark prepared in bark mills , and ...

Technology - Unity Behind Diversity - Blaise Alleyne
This is a quick fix for a problem I had when upgrading to Ubuntu 10.04, after having used the Mozilla PPA. The Firefox upgrade failed during ...

Cydia 紅黃字錯誤等常見問題解決方法
在亞洲人氣最旺的 《 iPhone News 愛瘋團 》 社團裡,三不五時會有越獄的瘋友反應 Cydia 出現紅字、黃字、無法安裝、載入過慢等錯誤問題。這篇整理一下 Cydia 常見的錯誤警告,方便遇到問題的瘋友查詢。其實 Cydia 出現紅黃字錯誤時,只要耐心看一下錯誤提示英文寫什麼,多半就能知道問題點在那,究竟是 ...

Acquisition P2P (for Mac OS X)
... Acquisition will not download files. When this happens, in the Terminal, type "kill -QUIT pid " where pid is the process ID of the Java subprocess ...

Guidelines for Choosing a Computer Language: Support for the Visionary Organization
Section 6 Choosing Software Development Products This is the second SASEA subprocess. It recognizes that a wise language choice cannot be made ...

AOL Lifestream : Search
AOL Lifestream Everything People Places View: All - Lifestream - Facebook - Twitter - YouTube Search results for “Store” . We found no results ...

NSTask Class Reference
Describes a task that runs as a subprocess.

Used Back End Process Equipment for Sale - Asseta
Browse Front End Processes Back End Processes Wafering Facilities PCB Assembly and Test Lab Equipment Electronic Test Machine Equipment List ...

Resources last updated: 3/24/2016 6:27:56 PM