Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.04; 'subject:changing': 0.07; 'filename': 0.09; 'subject:current': 0.09; 'subprocess': 0.09; '>>>': 0.12; 'wrote:': 0.14; 'default).': 0.16; 'argument': 0.16; 'keyword': 0.19; 'received:internal': 0.19; 'shell': 0.19; 'command': 0.19; 'header :In-Reply-To:1': 0.21; 'stuff': 0.22; 'received:10.202': 0.23; 'received:10.202.2': 0.23; 'received:66.111': 0.23; 'received:66.111.4': 0.23; 'received:messagingengine.com': 0.23; 'received:smtp.messagingengine.com': 0.23; 'fri,': 0.23; 'tried': 0.27; 'import': 0.29; 'hi,': 0.31; 'does': 0.33; 'to:addr:python- list': 0.33; '-0700,': 0.35; 'version.': 0.35; '(by': 0.37; 'but': 0.38; 'execute': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'skip:s 20': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'within': 0.60; 'skip:$ 10': 0.66; 'due': 0.67; 'message-id:@localhost.localdomain': 0.78; 'calls,': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=subject:from:to:date:in-reply-to:references:content-type:content-transfer-encoding:message-id:mime-version; s=smtpout; bh=veWOFV2DCaxgJTQojfsOE6+8MAA=; b=tbVDSC74ZvtAcyWn75RAv8f31wNDH9q1dyKWgVrDR2kCcSbW0rOwUhP0Y3tXdyTM0VYcBnFOeViwC2hRAYAp1I6z5VaqeaRMH/KgtNWFcUjWs+pA0X9h2sofZqbXgHp7xC4CVXx7MxMQYHtzQ0KIG4F3Ub3iNCbqQ4LjiAWujG4= X-Sasl-enc: 22pAenJTaOPd/gyhy/q5/KbNLN9vKJladxmFk8g1LeOK 1306534763 Subject: Re: changing current dir and executing a shell script From: Albert Hopkins To: python-list@python.org Date: Fri, 27 May 2011 18:19:22 -0400 In-Reply-To: References: Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAADBQTFRF1///CwsLGxsbJycnNzc3RUVFU1NTYmJicXFxf39/jIyMm5ubq6urubm5yMjI3t7eukg4JQAAAAF0Uk5TAEDm2GYAAAIoSURBVDhPpZC9btRQEEbPGIJQhOIZB4SEhGJ7W/42lihoKCJ6agoeglfgDXiQPAGEio5sKGgTLxRIFNk7DigV7FD4J4SW23jud+75ZA38x9ncnb3wf0PgjZnZdvo35rVZZWa3RiLDd+PGMNz5oABkw/2e9ne+HTgwGRt3nejHzc8Gk/EURfvx/IgLcK3YNZWB7C8vwFqtqcxEAPYD4CoAr5xUiBaJlfOrvTA+IRLqLhisWx/B9RItzckjHCJNxtqKGhRBgEiTAWCIBqGXDNBODEdBIWIEgquCiosD6GQsTYzAVVUAH0FCFDPP3ce8Byenx0hhFRBoX5cBFPXJUVILUog6rTOs5Mv5DnGyOAaXHMvb0fiU3z8QbNZAjmg5VXVbP/N0uHhyWJrAl8RYhebzVcq+K4CJ2WgomSbWsSsguRY6GtncD0N0EYImEcrRkPUxXcrKflNYN4LUmqKndQVOV5qOIDp5Vhb518oEqqxgBFuyOhSKlRF4NptPhp22Ee0ylnioNfVkPPLSix1SG9BJrRN4aFcevfNIKw8f8h5k8vtsnlUauSBiF2DD6/ePd5LPAOvzHpw97F6+dbHOk1T1X4DnXN2rlF+OWKXAuN3Cj3HHNW5u/13FzeQtEkv/YU0vDCATjZSn8KqZXwLdA3Kny+q6GZoGwPPFmZ5oNWt29TK4/XSVpK6bPRny4a+Qx1+FrNkrdATji/XHhdTbw55gMrC0TaFTEfwB/cbNxoZIacsAAAAASUVORK5CYII= Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.1 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 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: 25 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306534772 news.xs4all.nl 49042 [::ffff:82.94.164.166]:42425 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6437 On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > Hi, > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') > You don't want to do this because "cd" is a built-in shell command, and subprocess does not execute within a shell (by default). The proper way to do this is to use the "cwd" keyword argument to subprocess calls, i.e.: >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") -a