Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86165

Re: calling subprocess

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'argument': 0.05; 'args': 0.07; 'assign': 0.07; 'prefix': 0.09; 'true)': 0.09; 'cc:addr :python-list': 0.11; 'bug': 0.12; 'changes': 0.15; '(it': 0.16; '23,': 0.16; 'args,': 0.16; 'code?': 0.16; 'complain,': 0.16; 'debugging:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'spawn': 0.16; 'url:catb': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'feb': 0.22; 'import': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'exists': 0.24; 'recognize': 0.24; 'tend': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; '[1]': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'work.': 0.31; 'code': 0.31; 'terminate': 0.31; 'them?': 0.31; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'keyword': 0.36; 'doing': 0.36; 'url:org': 0.36; 'list': 0.37; 'rather': 0.38; 'does': 0.39; 'how': 0.40; 'affect': 0.61; "you're": 0.61; 'first': 0.61; 'making': 0.63; 'name': 0.63; 'real': 0.63; 'refer': 0.63; 'here': 0.66; 'side': 0.67; 'us,': 0.73; '2015': 0.84; 'adopting': 0.84; 'execution.': 0.84; 'approach.': 0.91; 'shell,': 0.91; 'to:none': 0.92; 'have.': 0.93
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=aonfsdjlbtaUnTnzr+bNm1DVQ6GFBXm73kYwSVgtLig=; b=RqPTwjXgouy+Rv1Q/GLFKOnYhy5kUKc1w2+NWbKhExmm1U5o5hUer75ghJ5W0d6tMJ crT98n2kj2OsYrfkcvIK75BvTVHOb4BHzgv1BW3CEr5CBUP4PghjrydRPTfJ6yBbaEvj THGvWeVpZfy7S8As1jOe6c4V5gc1+VZkYaqCNMfHHV4k1LUkmKXcmSXwBdDm4Je0XODC 9kDngRHtGnuPg+1l1BGZHQvIBv+ly88EKvA1zjnyUe7wx+SniSnM0ejLJ6VAq4XQEnez ZfZanNHZHX5LeBhvUfwt1Yeyx8F1pWSO+tmXu26pF7vKjT5wvjszYIvK+y6FLbOxK7et 3RGQ==
MIME-Version 1.0
X-Received by 10.50.79.161 with SMTP id k1mr9439175igx.14.1424643714947; Sun, 22 Feb 2015 14:21:54 -0800 (PST)
In-Reply-To <edfc56d5-8696-49d0-8b71-69044bbab1f5@googlegroups.com>
References <edfc56d5-8696-49d0-8b71-69044bbab1f5@googlegroups.com>
Date Mon, 23 Feb 2015 09:21:54 +1100
Subject Re: calling subprocess
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.19035.1424643724.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424643724 news.xs4all.nl 2935 [2001:888:2000:d::a6]:42885
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86165

Show key headers only | View raw


On Mon, Feb 23, 2015 at 9:06 AM,  <jkuplinsky@gmail.com> wrote:
> I thought this would be easy:
>
>
> for subprocess import call
> call (['cd', r'C:\apps'], shell = True)
>
>
> It doesn't work -- tried with/without prefix r, escaped backslashes, triple quotes, str(), .. nothing seems to work (it doesn't complain, but it doesn't change directories either) -- what am I doing wrong?

It does work. But what it does is spawn a shell, change the working
directory _of that shell_, and then terminate it. The working
directory change won't apply to your process.

It sounds to me like you're adopting a "shotgun debugging" [1]
approach. If you don't know what your changes are going to do, why are
you making them? I recommend, instead, a policy of examination and
introspection - what I tend to refer to as IIDPIO debugging: If In
Doubt, Print It Out. The first argument to subprocess.call() is a list
of parameters; you can assign that to a name and print it out before
you do the call:

from subprocess import call
args = ['cd', r'C:\apps']
print(args)
call(args, shell=True)

Now do all your permutations of args, and see what effect they have.
If the printed-out form is identical, there's no way it can affect the
subprocess execution.

Side point: *Copy and paste* your code rather than retyping it. The
keyword here is "from", not "for", and if we can't depend on the code
you're showing us, how can we recognize whether or not a bug exists in
your real code?

ChrisA

[1] http://www.catb.org/jargon/html/S/shotgun-debugging.html

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

calling subprocess jkuplinsky@gmail.com - 2015-02-22 14:06 -0800
  Re: calling subprocess Tim Golden <mail@timgolden.me.uk> - 2015-02-22 22:14 +0000
  Re: calling subprocess Chris Angelico <rosuav@gmail.com> - 2015-02-23 09:21 +1100
    Re: calling subprocess jkuplinsky@gmail.com - 2015-02-22 17:13 -0800
      Re: calling subprocess Chris Angelico <rosuav@gmail.com> - 2015-02-23 12:31 +1100
      Re: calling subprocess Dave Angel <davea@davea.name> - 2015-02-22 21:38 -0500
      Re: calling subprocess Dave Angel <davea@davea.name> - 2015-02-22 22:07 -0500

csiph-web