Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'string': 0.09; 'subject:skip:t 10': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'argument.': 0.16; 'file"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'command': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'interface': 0.32; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'list.': 0.37; 'pm,': 0.38; 'does': 0.39; 'pardon': 0.84; 'partially': 0.84; 'to:none': 0.92 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:cc :content-type; bh=NaGfdD3FvAoumnIBpp/v4Spe1Pds5+2H5M5rgiO0ipw=; b=KFXlKFWQqA29c9MdeZ/YcrbvWLAC2x9RPQRdJoqZvbTg6XPx7XS0IJ+QJEYfaQuSBo Mn1zmf4RfDjIjkeUkzF+4a0B4LPPj2+hODbDH07DPYfJspJlyym1oDBh9ARdsW8KPdDa ujae1o4irSlMNmTEONS0l+/PYzFW779+pWVXKwiDRY46Sh5sIGySnqUWtBkvqItB4gjc azFvMgfp8/3AViOl4uOT5FHCj8L67WJK4PwIx4e70/1Wg8nkN/8vEhPt8qXq4RqHuLiC JKXbBYIcZelJBXorLigRdsfrKysm25UtF60QtmZ2t4SRrI78gM/w4wUbBlBMD8TN/wOA nnJQ== MIME-Version: 1.0 X-Received: by 10.52.52.168 with SMTP id u8mr12980093vdo.25.1402913179765; Mon, 16 Jun 2014 03:06:19 -0700 (PDT) In-Reply-To: <539EBF61.4050106@rece.vub.ac.be> References: <539EBF61.4050106@rece.vub.ac.be> Date: Mon, 16 Jun 2014 20:06:19 +1000 Subject: Re: line to argv transformation From: Chris Angelico Cc: Pyton List Content-Type: text/plain; charset=UTF-8 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402913181 news.xs4all.nl 2876 [2001:888:2000:d::a6]:46563 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73308 On Mon, Jun 16, 2014 at 7:56 PM, Antoon Pardon wrote: > I am looking for an interface that takes a string as argument. The > string is to be treated as if it is a command line and transformed into > an argv list. > > "ls file" -> ['ls', 'file'] > "ls *.py" -> ['ls', 'file1.py', 'file2.py', ...] > "ls '*.py'" -> ['ls', '*.py'] > > Does something like this already exist? I looked around but seem to find > only things only partially do things like this, like shlex.split. def shell_split(cmd): return subprocess.check_output("""python -c 'import sys; print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0") :) ChrisA