Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '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; '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; 'skip:p 30': 0.29; 'am,': 0.29; 'mode': 0.30; 'message- id:@mail.gmail.com': 0.30; '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; 'subject:?': 0.36; 'should': 0.36; 'thank': 0.38; 'pm,': 0.38; '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=vJAm9l3BCIl/d+pJiwc9EaexVbE6Uuxf57gosMN3j6w=; b=Wf4c/xnV05pCXWUYhMNTFTGkl/8d3NKWAgd5JylE4RkEPCdd+YWk04wdG0CtP9YZvy ZwvCsZpN3crQ1VwM3jo06jMZZb5cBxItn7VaW9OhjxWTZU0RCopIx5Tcd7Hhu3JTPuM+ r5/skZVhnfk3DtV+wJKC7VBoq3h/t8Zq89rke8Ghs+TEyLZXM7xz939KfgEsW6xkINWo JMIPG1YI7mIgxR/xBj6zsd8QRiHZxzAemJE6ne75+shw7AsQBavT9hmV14wVvIgonC0E eoei9B8evkpsCi0KNsO6Utlwh6bAf1ZUOwa7Vkh9mo5JPpMTNlCVgPzBjlTfAaC29Wpv dGww== MIME-Version: 1.0 X-Received: by 10.220.169.146 with SMTP id z18mr95904vcy.58.1388852967656; Sat, 04 Jan 2014 08:29:27 -0800 (PST) In-Reply-To: References: Date: Sat, 4 Jan 2014 11:29:27 -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=001a11c28b54c850f904ef278796 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: 89 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388852975 news.xs4all.nl 2903 [2001:888:2000:d::a6]:54397 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63136 --001a11c28b54c850f904ef278796 Content-Type: text/plain; charset=ISO-8859-1 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 > --001a11c28b54c850f904ef278796 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you so much Jerry.
I should have read though the= man page more carefully.
The available online cscope tutorials n= ever 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

--001a11c28b54c850f904ef278796--