Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'output': 0.04; 'bash': 0.07; 'escape': 0.07; 'file)': 0.07; 'performs': 0.07; "subject:' ": 0.07; 'trailing': 0.07; 'backslash': 0.09; 'formed': 0.09; 'literal': 0.09; 'splitting': 0.09; 'subject:extra': 0.09; 'substitution': 0.09; 'terminates': 0.09; 'sat,': 0.15; "'c:\\\\'": 0.16; 'command,': 0.16; 'command;': 0.16; 'deleted,': 0.16; 'echo': 0.16; 'file).': 0.16; 'nest': 0.16; 'newlines': 0.16; 'old-style': 0.16; 'parentheses': 0.16; 'pathname': 0.16; 'retains': 0.16; 'right:': 0.16; 'wrote:': 0.17; 'deleted.': 0.17; 'replacing': 0.17; 'jan': 0.18; 'shell': 0.18; 'appears': 0.18; 'equivalent': 0.20; 'followed': 0.20; 'to:name :python-list@python.org': 0.20; 'skip:- 40': 0.21; 'cheers': 0.24; 'command': 0.24; 'allows': 0.25; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'embedded': 0.27; 'handling': 0.27; 'used,': 0.27; 'wonder': 0.27; 'executing': 0.27; 'expansion': 0.27; 'replace': 0.27; 'correct': 0.28; '>>>>': 0.29; 'whitespace': 0.29; 'date:': 0.29; 'url:mailman': 0.29; 'case,': 0.29; 'manual': 0.29; 'skip:_ 10': 0.29; "skip:' 10": 0.30; 'url:python': 0.32; "skip:' 20": 0.32; 'url:listinfo': 0.32; 'point,': 0.33; 'quotes': 0.33; 'surely': 0.33; 'to:addr:python- list': 0.33; 'faster': 0.35; 'replaced': 0.35; 'subject:?': 0.35; 'similar': 0.35; 'there': 0.35; 'subject:': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'characters': 0.36; 'email addr:python.org': 0.36; 'possible': 0.37; 'two': 0.37; 'from:': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'end': 0.40; 'url:mail': 0.40; 'your': 0.60; 'from:no real name:2**0': 0.60; 'first': 0.61; 'email name:python-list': 0.62; 'between': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; 'within': 0.64; 'absolutely': 0.84; '+1100': 0.84; '--->': 0.84; '2013': 0.84; 'confirms': 0.91; 'piping': 0.91; 'subject:skip:s 20': 0.91 X-EIP: [9UGdZfsHzZ2B4o6x9gMh99sBcEZJG+RCxyYXpACUf4Q=] X-Originating-Email: [sbremal@hotmail.com] From: To: "python-list@python.org" Subject: RE: 'subprocess.check_output' extra new line? Date: Fri, 4 Jan 2013 17:51:33 +0000 Importance: Normal In-Reply-To: References: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 04 Jan 2013 17:51:34.0279 (UTC) FILETIME=[22C9A970:01CDEAA4] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 77 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357321962 news.xs4all.nl 6868 [2001:888:2000:d::a6]:35244 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36124 Very good point=2C you are absolutely right: # cygpath C:\\ | od -c 0000000 / c y g d r i v e / c \n 0000014 'bash' manual also confirms it: Command Substitution Command substitution allows the output of a command to replace the = command name. There are two forms: $(command) or `command` Bash performs the expansion by executing command and replacing = the command substitution with the ---> standard output of the command=2C with any trailing newlines = deleted. Embedded newlines are not deleted=2C but they may be removed during word splitting. The comm= and substitution $(cat file) can be replaced by the equivalent but faster $(< file). When the old-style backquote form of substitution is used=2C backsl= ash retains its literal meaning except when followed by $=2C `=2C or \. The first backquote not p= receded by a backslash terminates the command substitution. When using the $(command) form=2C all charact= ers between the parentheses make up the command=3B none are treated specially. Command substitutions may be nested. To nest when using the backqu= oted form=2C escape the inner back- quotes with backslashes. If the substitution appears within double quotes=2C word splitting a= nd pathname expansion are not per- formed on the results. Cheers B. ---------------------------------------- > Date: Sat=2C 5 Jan 2013 03:14:46 +1100 > Subject: Re: 'subprocess.check_output' extra new line? > From: rosuav@gmail.com > To: python-list@python.org > > On Sat=2C Jan 5=2C 2013 at 2:50 AM=2C wrote: > > > > Hi > > > > I wonder if the additional new line charachter at the end of the standa= rd output capture is on purpose with 'subprocess.check_output'? > > > >>>> subprocess.check_output([ 'cygpath'=2C 'C:\\' ]) > > '/cygdrive/c\n' > > > > If I do the same from the shell there is no extra new line (which is co= rrect I believe): > > > > $ x=3D$(cygpath C:\\)=3B echo "_${x}_" > > _/cygdrive/c_ > > > > Surely I have a workaround. I was more interested whether it was a desi= gn flaw. > > What you may have there is the shell $( ) handling changing the > program's output. Try piping the command into 'hd' or similar to see > what it actually produces=3B it's entirely possible the \n is there=2C an= d > the shell is stripping it. > > In any case=2C you can easily trim whitespace from inside Python. That > would be your workaround=2C I think. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list =