Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'attributes,': 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; 'wrote:': 0.18; 'command': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'looks': 0.24; 'cc:2**0': 0.24; 'right.': 0.26; 'header:In-Reply- To:1': 0.27; 'skip:p 30': 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; 'pm,': 0.38; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'such': 0.63; 'to:addr:gmail.com': 0.65; 'results': 0.69; 'write()': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=lG9FHhBOPyakUVB+gGBxBdMm4ODcZ4eZ97f/KybjtdE=; b=e7wYdQvUP//hGbJZxGh93cm80QWec//5LH8YTM2NZyBU3hyk5XOw66nQdXRlwv+73f Nsd8UI7e9nnvkoI/T4b3Kp6jng3bH+zDaT5LN0rwMmiUjwMCk+TrxhPoGvm5y3Nh/O+n FY9VbPFdTvWf8kWtW/0DK+NDlzo1znxX41TkX6CqoDJC6iO9Ps/9UyLoQIxFNessCeyX dwSxdjz8In4xm4OElDB/ip8w/pZB49m63N6qme7wYSnrHcZk2YfGdKCvf01oZ/coLwHZ dJVHzGV4B7RElwFRHyMCDWFMOiTMWoiP9wJ+lA0pnPAIa5+AbgnNwycpw2pwEnoVQQPQ wGXA== MIME-Version: 1.0 X-Received: by 10.68.143.100 with SMTP id sd4mr86014721pbb.0.1388817326314; Fri, 03 Jan 2014 22:35:26 -0800 (PST) In-Reply-To: References: Date: Sat, 4 Jan 2014 01:35:26 -0500 Subject: Re: How to make a tkinter GUI work on top of a CUI program? From: Jerry Hill To: li.beinan@gmail.com Content-Type: text/plain; charset=UTF-8 Cc: "python-list \(General\)" 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: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388817335 news.xs4all.nl 2954 [2001:888:2000:d::a6]:50068 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63113 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