Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; '64-bit': 0.07; 'arguments': 0.07; 'exit': 0.07; 'python': 0.09; 'explanation': 0.09; 'itself,': 0.09; 'returncode': 0.09; 'advance': 0.10; '2.7': 0.13; 'created.': 0.16; 'exe': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'subject:exe': 0.16; 'subprocess': 0.16; 'wrote:': 0.17; 'code,': 0.18; 'versions': 0.20; 'import': 0.21; 'supposed': 0.21; 'example': 0.23; 'second': 0.24; 'tried': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'skip:( 20': 0.28; '(used': 0.29; 'code': 0.31; 'file': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'instead,': 0.33; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'something': 0.35; 'but': 0.36; 'guidance': 0.36; 'subject:with': 0.36; 'execute': 0.37; 'passed': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'below,': 0.60; 'further': 0.61; 'different': 0.63; 'offer': 0.65; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=XeZXOvF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=lN3DmIIylWMA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=IGZP1A3-2mUA:10 a=ejYao4tBGCN1mRrHpYAA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Wed, 30 Jan 2013 18:11:51 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: how to use subprocess to execute an exe with args and an output References: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> In-Reply-To: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 1359569513 news.xs4all.nl 6906 [2001:888:2000:d::a6]:58616 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37951 On 2013-01-30 17:15, noydb wrote: > I am looking for some guidance on using subprocess to execute an EXE with arguments and an output. The below code works in that it returns a 0 exit code, but no output file is created. I have tried a few different versions of this code (used Popen instead, some stderr/stdout), but no luck. Can anyone offer an explanation or suggestion? (GPSBabel is freeware) > Python 2.7 on windows7 64-bit > > import subprocess > subprocess.call([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", > "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", > "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"]) > > If I use this below, I get a returncode of 1, exit code of 0. > import subprocess > x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", > "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", > "-o", "gpx", r"C:\Temp\gpx\test28output.gpx", > "shell=True", "stdout=subprocess.PIPE", "stderr=subprocess.PIPE"]) > > x.wait() > print x.returncode > > Thanks in advance for any help > The second example is incorrect. The parts starting from "shell" are supposed to be further arguments for Popen itself, not something passed to "gpsbabel.exe": x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)