Skip to content Skip to sidebar Skip to footer

Passing Double Quotation Marks To A Command From Python Using The Subprocess Module

I have a command line program I'm using from within a Python script to take care of stamping a build number onto an executable. This is the command line program: http://www.elphin.

Solution 1:

try this script sub.py:

#! /usr/bin/pythonimport sys
from subprocess import check_output

iflen(sys.argv) > 1:
    print sys.argv
else:
    print check_output((sys.argv[0], '-f"1234"'))

then run it:

./sub.py

it return what we gave:

['./sub.py', '-f"1234"']

So I guess check_output works just fine, the problem may came from how StampVer.exe handle parameter, you can try

file_version_arg = '-f{0}'.format(version_number)

Solution 2:

My solution ended up being kind of a cop-out. Despite the documentation for StampVer showing the format above for the version number in all examples, it turns out you can just leave the quotes out all together and even space it out from the -f switch and it will still be accepted.

I'm going to call this my answer but I still think being able to pass quotes through subprocess is a worthwhile problem to figure out. If anyone has an answer that will actually solve the initial problem then please post it and I'll mark it instead.

Post a Comment for "Passing Double Quotation Marks To A Command From Python Using The Subprocess Module"