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


Groups > comp.lang.python > #36116

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!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'output': 0.04; "subject:' ": 0.07; 'subject:extra': 0.09; 'sat,': 0.15; "'c:\\\\'": 0.16; 'echo': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'shell': 0.18; 'command': 0.24; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'handling': 0.27; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'received:209.85.212': 0.28; '>>>>': 0.29; 'whitespace': 0.29; 'case,': 0.29; 'skip:_ 10': 0.29; "skip:' 10": 0.30; "skip:' 20": 0.32; 'surely': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'subject:?': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'possible': 0.37; 'received:209': 0.37; 'there,': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'your': 0.60; 'more': 0.63; '2013': 0.84; 'piping': 0.91; 'subject:skip:s 20': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=DegHaotN7hxQ72CAfG47CZSaPGjH44tyYAa3FnYR6WQ=; b=jyQ3T76hkrzCFJLUo+x0l3yTB/irRVgQ4VK2yAoX5rrQqrryco/1UlvmZDPEfEuKyp O2E2nUhnhKJa0gYdHWtjoAGAu26ln+VMoQupzC4TUpZZSxGGOD7jn58l2aX8tnUs4Rww UFdLJDxGhZMlpBtUKn6LmDa3WQubcn1frJDpSUhawMveeRbQBLY2MVwbicUaay2e+Pbs +RFFDMNofALF4bV+Wmda+tX2686KNQSPsDGzwW1uAsnQ00WvO9PYMjmY688MSHOUujyr KACJ2OdS2aV82kM00f8kqgPKAs2q054Gl+dgS9VHRKoGtaX0CqSbVjvnC1o0mqsxpOTU mG2w==
MIME-Version 1.0
In-Reply-To <DUB104-W4038B02983B651FA249D17A9200@phx.gbl>
References <DUB104-W4038B02983B651FA249D17A9200@phx.gbl>
Date Sat, 5 Jan 2013 03:14:46 +1100
Subject Re: 'subprocess.check_output' extra new line?
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.88.1357316089.2939.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357316089 news.xs4all.nl 6989 [2001:888:2000:d::a6]:53488
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36116

Show key headers only | View raw


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

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


Thread

Re: 'subprocess.check_output' extra new line? Chris Angelico <rosuav@gmail.com> - 2013-01-05 03:14 +1100

csiph-web