Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'true,': 0.04; 'case.': 0.05; 'level,': 0.07; 'python': 0.09; 'etc).': 0.09; 'mess': 0.09; 'referencing': 0.09; 'stdout': 0.09; 'stringio': 0.09; 'sys.stdout': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'subject:python': 0.11; 'file,': 0.15; '(so,': 0.16; 'buffering,': 0.16; 'dup2': 0.16; 'fiddle': 0.16; 'goal,': 0.16; 'output?': 0.16; 'sees': 0.16; 'way;': 0.16; 'otherwise,': 0.20; 'sort': 0.21; 'fairly': 0.21; 'assuming': 0.22; 'pipe': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'separate': 0.27; 'c++': 0.27; 'easiest': 0.27; "doesn't": 0.28; 'there.': 0.28; 'chris': 0.28; 'i/o': 0.29; 'case,': 0.29; 'code': 0.31; '(and': 0.32; 'file': 0.32; 'running': 0.32; 'function.': 0.33; 'problem': 0.33; '(with': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'process,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; "i'll": 0.36; 'usual': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'your': 0.60; 'high': 0.61; 'assistance': 0.63; 'offer': 0.65; 'physical': 0.69; 'etc,': 0.84; 'redirecting': 0.84; 'start.': 0.84 X-Received: by 10.49.87.9 with SMTP id t9mr1278584qez.16.1358437902727; Thu, 17 Jan 2013 07:51:42 -0800 (PST) Newsgroups: comp.lang.python Date: Thu, 17 Jan 2013 07:51:42 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=88.0.45.190; posting-account=P89KwwoAAAC1gWXk_7S15RVmaOYKQ_0D References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 88.0.45.190 MIME-Version: 1.0 Subject: Re: python sys.stdout and C++ iostreams::cout From: Utpal Sarkar To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358437912 news.xs4all.nl 6955 [2001:888:2000:d::a6]:35019 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36948 Thanks a lot Chris and Nobody! I'll have a look at dup2 for a start. > > I was assuming that sys.stdout would be referencing the same physical stream as iostreams::cout running in the same process, but this doesn't seem to be the case. > > > > That's more-or-less true, but there will likely be separate buffering, > > so even without redirection you might see some oddities. But the > > problem with your code is that you're not actually redirecting stdout > > in any way; you're catching, at a fairly high level, everything that > > Python would otherwise have sent there. > > > > Is there any way that you can get the C++ code to offer a way to > > redirect its output? Otherwise, you're going to have to fiddle around > > with the usual mess of I/O redirection (with dup2), and you can only > > send it to what the OS sees as a file (so, no StringIO buffer). So to > > achieve your goal, you may need either a temporary physical file, or > > some sort of pipe (and worry about reading from it before it fills up, > > etc, etc). There may be alternatives, but in any case, the easiest way > > is going to be with some assistance from the C++ function. > > > > ChrisA