Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36124

RE: 'subprocess.check_output' extra new line?

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 <sbremal@hotmail.com>
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 <sbremal@hotmail.com>
To "python-list@python.org" <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 <CAPTjJmpSv_D45MpPydprVoUQDN4BQKweQVenA1ODBehEmT-g-g@mail.gmail.com>
References <CAPTjJmpSv_D45MpPydprVoUQDN4BQKweQVenA1ODBehEmT-g-g@mail.gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.92.1357321962.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


Very good point, 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, with any  trailing  newlines  deleted.   Embedded  newlines  are  not
       deleted,  but they may be removed during word splitting.  The command substitution $(cat file) can be
       replaced by the equivalent but faster $(< file).
       When the old-style backquote form of substitution is used,  backslash  retains  its  literal  meaning
       except  when  followed by $, `, or \.  The first backquote not preceded by a backslash terminates the
       command substitution.  When using the $(command) form, all characters between the parentheses make up
       the command; none are treated specially.
       Command  substitutions may be nested.  To nest when using the backquoted form, escape the inner back-
       quotes with backslashes.
       If the substitution appears within double quotes, word splitting and pathname expansion are not  per-
       formed on the results.

Cheers
B.

----------------------------------------
> Date: Sat, 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, Jan 5, 2013 at 2:50 AM, <sbremal@hotmail.com> wrote:
> >
> > Hi
> >
> > I wonder if the additional new line charachter at the end of the standard output capture is on purpose with 'subprocess.check_output'?
> >
> >>>> subprocess.check_output([ 'cygpath', 'C:\\' ])
> > '/cygdrive/c\n'
> >
> > If I do the same from the shell there is no extra new line (which is correct I believe):
> >
> > $ x=$(cygpath C:\\); echo "_${x}_"
> > _/cygdrive/c_
> >
> > Surely I have a workaround. I was more interested whether it was a design 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; it's entirely possible the \n is there, and
> the shell is stripping it.
>
> In any case, you can easily trim whitespace from inside Python. That
> would be your workaround, I think.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list 		 	   		  

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: 'subprocess.check_output' extra new line? <sbremal@hotmail.com> - 2013-01-04 17:51 +0000

csiph-web