Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47593
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'output': 0.05; 'sys': 0.07; 'interim': 0.09; 'iterate': 0.09; 'output,': 0.09; 'python': 0.11; '2.7': 0.14; 'windows': 0.15; 'grep': 0.16; 'minus': 0.16; 'received:74.208.4.195': 0.16; 'subject:windows': 0.16; 'wrote:': 0.18; '(not': 0.18; 'meant': 0.20; 'seems': 0.21; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'adds': 0.24; 'convenient': 0.24; 'file.': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'leave': 0.29; 'lines': 0.31; 'index,': 0.31; 'linux.': 0.31; 'trivial': 0.31; 'anyone': 0.31; 'file': 0.32; 'there.': 0.32; 'front': 0.32; 'open': 0.33; 'guess': 0.33; 'maybe': 0.34; 'could': 0.34; 'common': 0.35; 'problem.': 0.35; 'something': 0.35; 'but': 0.35; 'doing': 0.36; "i'll": 0.36; 'easily': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'simply': 0.61; 'simple': 0.61; 'first': 0.61; "you've": 0.63; 'real': 0.63; 'more': 0.64; 'detail.': 0.68; 'received:74.208': 0.68; 'hoping': 0.75 |
| Date | Mon, 10 Jun 2013 15:46:24 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Popen and reading stdout in windows |
| References | <fc7fe12873ac476280f4d02714470fb5@exch.activenetwerx.com> |
| In-Reply-To | <fc7fe12873ac476280f4d02714470fb5@exch.activenetwerx.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:e5YEGy5qVu9qwybJuM43ZMtBPeYj6SsToDWAeXpGSDy EStpvZP0hnN34u4tr9ubw2Ls7wScqpFNSnK9arG+O7KpcEb2sa mZmRf4qnVnnQ3QpLyLeEv2ulZ/EEsk6N4Efl0qQJGerYsluTCD g76MsvAP4PbTUnUDuW+pxqo4ti/XoKhTZ89/Xnz1vvlZL3c3QZ 41n7H1UuD8Ri4i9EcBRJP+n/s3V+EGZagRSFfzofBYeMNJ8LHI 8/ZZINFmvDmj0pIqkSPF36tFQM+O9IkuuB4cuiZs6cNcasvXb/ P6GhiZnQwVGqplnFx2kWM5BSVKOaEVK84al0GZaPJ6/1GJAlg= = |
| 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.2982.1370893598.3114.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370893598 news.xs4all.nl 15892 [2001:888:2000:d::a6]:36448 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47593 |
Show key headers only | View raw
On 06/10/2013 02:37 PM, Joseph L. Casale wrote:
> I have a use where writing an interim file is not convenient and I was hoping to
> iterate through maybe 100k lines of output by a process as its generated or
> roughly anyways.
>
> Seems to be a common question on ST, and more easily solved in Linux.
> Anyone currently doing this with Python 2.7 in windows and can share some
> guidance?
>
You leave out an awful amount of detail. I have no idea what ST is, so
I'll have to guess your real problem.
You've got a process (myprog.exe) which generates a medium amount of
output to stdout, and you want to process that data in a python program
as it's being output, but without first writing it to a file.
If by process you meant grep, the answer would be as simple as
myprocess | grep parm1 parm2
But you want to write something (not called grep) in Python.
myprocess | python myfilter.py
The question is how to write myfilter.py
Answer is to use stdin as you would a file. it's already open for you,
and it'll get the data as it's being generated (plus or minus some
buffering). So you can simply do something like:
import sys
for index, line in enumerate(sys.stdin):
print index, line
This trivial "filter" adds a line number in front of every line. But
you could do anything there. And you might not need enumerate if you
don't care about the line number.
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Popen and reading stdout in windows Dave Angel <davea@davea.name> - 2013-06-10 15:46 -0400
csiph-web