Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run a command with %?

I am trying to run command git log origin/master..HEAD --format=format:"%H" in python as below but running into below error,I tried to escape % but that doesn’t fix the error, any idea how to fix it?

def runCmd2(cmd):
    logger.info("Running command %s"%cmd)
    proc = Popen(cmd ,universal_newlines = True, shell=True, stdout=PIPE, stderr=PIPE)
    (output, error) = proc.communicate()
    return output.strip(),error.strip()

def get_local_commits():
    """Get local commits """
    branch = "master"
    cmd = "git log origin/%s..HEAD  --format=format:\"%H\" "%(branch)
    output,error = runCmd2(cmd)
    return output,error

ERROR:-

  File "/Users/gnakkala/jitsuin/wifi-ci/enable_signing.py", line 45, in get_local_commits
    cmd = "git log origin/%s..HEAD  --format=format:\"%H\" "%(branch)
TypeError: not enough arguments for format string

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To escape % you double it, using %%

branch = "master"
cmd = 'git log origin/%s..HEAD  --format=format:"%%H"' % branch
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading