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


Groups > comp.lang.python > #37945 > unrolled thread

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

Started bynoydb <jenn.duerr@gmail.com>
First post2013-01-30 09:15 -0800
Last post2013-01-30 14:58 -0500
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  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

#37945 — how to use subprocess to execute an exe with args and an output

Fromnoydb <jenn.duerr@gmail.com>
Date2013-01-30 09:15 -0800
Subjecthow to use subprocess to execute an exe with args and an output
Message-ID<7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com>
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

[toc] | [next] | [standalone]


#37947

Fromnoydb <jenn.duerr@gmail.com>
Date2013-01-30 09:19 -0800
Message-ID<9053e859-871d-4fc6-8bed-f9be1a5f966c@googlegroups.com>
In reply to#37945
To add on, I need to eventually write a script that takes input, feeds it into this exe, and takes the output file to perform more 'tools'/manipulations on it.  Is call or Popen called for, why?  Or maybe some other module???

[toc] | [prev] | [next] | [standalone]


#37948

FromChris Rebert <clp2@rebertia.com>
Date2013-01-30 09:57 -0800
Message-ID<mailman.1218.1359568648.2939.python-list@python.org>
In reply to#37945
On Wed, Jan 30, 2013 at 9:15 AM, noydb <jenn.duerr@gmail.com> 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 my cursory reading of GPSBabel's documentation is right, you're
missing a "-F" before the output filepath. Try:

subprocess.call([
    r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe",
    "-i", "gdb",
    "-f", r"C:\Temp\GDBdata\testgps28.gdb",
    "-o", "gpx",
    "-F", r"C:\Temp\gpx\test28output.gpx",
])

Regards,
Chris

[toc] | [prev] | [next] | [standalone]


#37951

FromMRAB <python@mrabarnett.plus.com>
Date2013-01-30 18:11 +0000
Message-ID<mailman.1222.1359569513.2939.python-list@python.org>
In reply to#37945
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)

[toc] | [prev] | [next] | [standalone]


#37952

Fromnoydb <jenn.duerr@gmail.com>
Date2013-01-30 10:40 -0800
Message-ID<a6618e11-c234-4552-8ee1-eb71bfe5bcbd@googlegroups.com>
In reply to#37945
oh DUH!  that was it, just missing the -F.  Thank-you!!

[toc] | [prev] | [next] | [standalone]


#37956

FromTerry Reedy <tjreedy@udel.edu>
Date2013-01-30 14:58 -0500
Message-ID<mailman.1225.1359575925.2939.python-list@python.org>
In reply to#37945
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web