Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36116 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-01-05 03:14 +1100 |
| Last post | 2013-01-05 03:14 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: 'subprocess.check_output' extra new line? Chris Angelico <rosuav@gmail.com> - 2013-01-05 03:14 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-05 03:14 +1100 |
| Subject | Re: 'subprocess.check_output' extra new line? |
| Message-ID | <mailman.88.1357316089.2939.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
Back to top | Article view | comp.lang.python
csiph-web