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


Groups > comp.lang.python > #37956

Re: how to use subprocess to execute an exe with args and an output

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'mrab': 0.05; '64-bit': 0.07; 'arguments': 0.07; 'exit': 0.07; 'python': 0.09; 'explanation': 0.09; 'itself,': 0.09; 'processing,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'returncode': 0.09; 'terry': 0.09; 'advance': 0.10; '2.7': 0.13; 'created.': 0.16; 'exe': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:exe': 0.16; 'subprocess': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'shell': 0.18; '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; 'header:X-Complaints-To:1': 0.28; '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; 'needed': 0.35; 'pm,': 0.35; 'something': 0.35; 'received:org': 0.36; '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; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'think': 0.40; 'below,': 0.60; 'further': 0.61; 'different': 0.63; 'offer': 0.65; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: how to use subprocess to execute an exe with args and an output
Date Wed, 30 Jan 2013 14:58:19 -0500
References <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> <51096267.4040604@mrabarnett.plus.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <51096267.4040604@mrabarnett.plus.com>
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1225.1359575925.2939.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359575926 news.xs4all.nl 6889 [2001:888:2000:d::a6]:54000
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37956

Show key headers only | View raw


On 1/30/2013 1:11 PM, MRAB wrote:
> 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)
>

and it is apparently best to not use shell=True unless actually needed 
for shell processing, which I do not think is the case here.

-- 
Terry Jan Reedy

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


Thread

how to use subprocess to execute an exe with args and an output noydb <jenn.duerr@gmail.com> - 2013-01-30 09:15 -0800
  Re: how to use subprocess to execute an exe with args and an output noydb <jenn.duerr@gmail.com> - 2013-01-30 09:19 -0800
  Re: how to use subprocess to execute an exe with args and an output Chris Rebert <clp2@rebertia.com> - 2013-01-30 09:57 -0800
  Re: how to use subprocess to execute an exe with args and an output MRAB <python@mrabarnett.plus.com> - 2013-01-30 18:11 +0000
  Re: how to use subprocess to execute an exe with args and an output noydb <jenn.duerr@gmail.com> - 2013-01-30 10:40 -0800
  Re: how to use subprocess to execute an exe with args and an output Terry Reedy <tjreedy@udel.edu> - 2013-01-30 14:58 -0500

csiph-web