Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'object.': 0.09; 'wed,': 0.12; 'am,': 0.13; 'defined': 0.14; 'wrote:': 0.15; '4096': 0.16; 'cc:addr:python-list': 0.16; 'this:': 0.16; 'def': 0.16; 'aug': 0.19; 'true,': 0.19; 'command': 0.19; 'cheers,': 0.19; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'code': 0.24; 'received:209.85.220': 0.25; 'yourself.': 0.28; 'message-id:@mail.gmail.com': 0.28; 'shell': 0.29; 'cc:addr:python.org': 0.30; 'chris': 0.32; 'anyone': 0.33; 'doing': 0.37; 'could': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'think': 0.38; 'either': 0.39; 'received:209': 0.40; 'subject:The': 0.73; 'escaping': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=TSHNO0itwhM9YgbtLy3Ssi0L7g33qqczYrP0FVLNpG8=; b=RbKFysgxwvJ6f54wXqUZdPw8KRiBr9HZTiKSTQB9UCmQG/xvNi9SPS0DohYN5seZOz RyWgvjfclYMYuQ2y6AWhqWBC/KsAoF1GMo0wRAZ4hpNY2US7CeBoroyZRcLdADjlFomf 1K3wzDDOfizitfbyPXu213udZRINxrelNIsoU= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Date: Wed, 3 Aug 2011 10:27:41 -0700 X-Google-Sender-Auth: VFOs0mySD-PwuWiXvhmdEgmAHJg Subject: Re: Snippet: The leanest Popen wrapper From: Chris Rebert To: Phlip Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312392464 news.xs4all.nl 23951 [2001:888:2000:d::a6]:58823 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10818 On Wed, Aug 3, 2011 at 8:29 AM, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > =C2=A0 =C2=A0process =3D Popen( flatten(cmdz), flatten() being defined as...? > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 she= ll=3D True, I would strongly encourage you to avoid shell=3DTrue. You really don't want to have to worry about doing proper shell escaping yourself. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std= out=3D subprocess.PIPE, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std= err=3D subprocess.PIPE, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 buf= size=3D 4096 ) Cheers, Chris