Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36116
| References | <DUB104-W4038B02983B651FA249D17A9200@phx.gbl> |
|---|---|
| Date | 2013-01-05 03:14 +1100 |
| Subject | Re: 'subprocess.check_output' extra new line? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.88.1357316089.2939.python-list@python.org> (permalink) |
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
Re: 'subprocess.check_output' extra new line? Chris Angelico <rosuav@gmail.com> - 2013-01-05 03:14 +1100
csiph-web