Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'works.': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'attributes,': 0.16; 'carefully.': 0.16; 'event):': 0.16; 'mode,': 0.16; 'read()': 0.16; 'stdout': 0.16; 'subject:GUI': 0.16; 'subject:make': 0.16; 'subject:program': 0.16; 'subject:top': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'command': 0.22; 'email addr:gmail.com>': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'looks': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'right.': 0.26; 'tutorials': 0.26; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'mode': 0.30; 'message-id:@mail.gmail.com': 0.30; 'too.': 0.31; 'end,': 0.31; 'pipe': 0.31; 'probably': 0.32; 'fri,': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'thanks': 0.36; 'subject:?': 0.36; 'should': 0.36; 'thank': 0.38; 'pm,': 0.38; 'how': 0.40; 'read': 0.60; 'mentioned': 0.61; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'such': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'header:Reply-To:1': 0.67; 'results': 0.69; 'online': 0.71; 'reply-to:no real name:2**0': 0.71; 'reply- to:addr:gmail.com': 0.80; 'write()': 0.91; 'hill': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=QO03sNZ9YvhZ7IEzEKnB9rDOgM8vtVfexRRjQz30DMQ=; b=WRgFAICDQLkfsF/3aG8rt4X9qr9yP1Q+zpuJ/iJHIdCrgn5br5wgNy8llLCUvnXgzV k6LThAzZtv0cE/OwBXpwBraoTr+gcakT2BRykX1m7OVeLhu2UQi8gr9lYNnVdODBCpOz eLNCFyPI1bBO4MXXs9Ln4cX1acXM74Gxn0LNwQhEJak/CrLug6nfj6HPpADC4ysR60dR Sq88l4VENaR0JR8RHYkzC2X3RweF22N1W5ZDrsAjcz7GYLhICYdswB8STQhaEGBccKvi BoBy+AYGGEEsAGgZ/jzyu2uX31cmXQvdfK5iE0u632faCVsaUk9Gvhh3RnDNSYNgdUOt oQ+g== MIME-Version: 1.0 X-Received: by 10.221.33.206 with SMTP id sp14mr2614608vcb.29.1388853066809; Sat, 04 Jan 2014 08:31:06 -0800 (PST) In-Reply-To: References: Date: Sat, 4 Jan 2014 11:31:06 -0500 Subject: Re: How to make a tkinter GUI work on top of a CUI program? From: Beinan Li To: Jerry Hill Content-Type: multipart/alternative; boundary=001a11365136b1470804ef278ddf Cc: "python-list \(General\)" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: li.beinan@gmail.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 106 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388853075 news.xs4all.nl 2897 [2001:888:2000:d::a6]:57238 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63137 --001a11365136b1470804ef278ddf Content-Type: text/plain; charset=ISO-8859-1 ... and thanks to Chris too. Now I got the better idea how the subprocess module works. On Sat, Jan 4, 2014 at 11:29 AM, Beinan Li wrote: > Thank you so much Jerry. > I should have read though the man page more carefully. > The available online cscope tutorials never mentioned the line-oriented > mode. > > > > On Sat, Jan 4, 2014 at 1:35 AM, Jerry Hill wrote: > >> On Fri, Jan 3, 2014 at 9:44 PM, Beinan Li wrote: >> > But some console programs have their own shell or ncurse-like CUI, such >> as >> > cscope. >> > So I figured that I need to first subprocess.popen a bidirectional pipe >> and >> > send command through stdin and get results from stdout and stderr. >> > >> > But in such a case I found that communicate('cmd') will freeze. >> >> Right. communicate() waits for the subprocess to end, and the >> subprocess is still waiting for you to do something. Instead, you'll >> need to read() and write() to the subprocess' stdin and stdout >> attributes, probably something like this (untested): >> >> def OnClickBtn(self, event): >> print('OnClickBtn') >> self.subProc.stdin.write('symbolName\n') >> print(self.subProc.stdout.read()) >> >> It looks like cscope has both a screen-oriented mode and a line-based >> mode. When you're working with a subprocess like this, you're going >> to want to be in the line-based mode, so you'll probably want to add >> -l or -L to your command line. >> >> -- >> Jerry >> > > --001a11365136b1470804ef278ddf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
... and thanks to Chris too.
Now I got the better idea= how the subprocess module works.

On Sat, Jan 4, 2014 at 11:29 AM, Beinan Li = <li.beinan@gmail.com> wrote:
Thank you so much Jerry.I should have read though the man page more carefully.
The avai= lable online cscope tutorials never mentioned the line-oriented mode.



On Sat, Jan 4, 2014 at 1:35 AM, Jerry Hi= ll <malaclypse2@gmail.com> wrote:
On Fri, Jan 3, 2014 at 9:44 PM, Beinan Li <li.beinan@gmail.com> wrote:
> But some console programs have their own shell or ncurse-like CUI, suc= h as
> cscope.
> So I figured that I need to first subprocess.popen a bidirectional pip= e and
> send command through stdin and get results from stdout and stderr.
>
> But in such a case I found that communicate('cmd') will freeze= .

Right. =A0communicate() waits for the subprocess to end, and the
subprocess is still waiting for you to do something. =A0Instead, you'll=
need to read() and write() to the subprocess' stdin and stdout
attributes, probably something like this (untested):

def OnClickBtn(self, event):
=A0 =A0 print('OnClickBtn')
=A0 =A0 self.subProc.stdin.write('symbolName\n')
=A0 =A0 print(self.subProc.stdout.read())

It looks like cscope has both a screen-oriented mode and a line-based
mode. =A0When you're working with a subprocess like this, you're go= ing
to want to be in the line-based mode, so you'll probably want to add -l or -L to your command line.

--
Jerry


--001a11365136b1470804ef278ddf--