0

I am running the diff command on MAC as follows and it works fine but when I run through python the --exclude option doesn't work meaning the command output still lists files under /Users/username/FWIntegration/branch_4355c1/.git, can anyone suggest how to debug this or how to fix this

/usr/bin/diff -x '.*' -x 'tech' -rq /Users/username/FWIntegration/repo2mirror /Users/username/FWIntegration/branch_4355c1 --exclude=/Users/username/FWIntegration/branch_4355c1/.git/

Running from python

cmd = "/usr/bin/diff -x '.*' -x 'tech' -rq /Users/username/FWIntegration/repo2mirror /Users/username/FWIntegration/branch_4355c1 --exclude=/Users/username/FWIntegration/branch_4355c1/.git/"

output,error = runCmd(cmd)

def runCmd(cmd):
    out = ""
    err = ""
    logger.info("Running command %s"%cmd)
    proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE)
    try:
        with proc.stdout as stdout:
            for line in stdout:
                print line,
                out = out + line
                #android_loader_output+=line
                #if 'ERROR:' in line:
                    #print line
    except:
        print "%s failed"%cmd
        print traceback.format_exc()

    try:
        with proc.stderr as stderr:
            for line in stderr:
                print line,
                err = err + line
                #android_loader_output+=line
                #if 'ERROR:' in line:
                    #print line
    except:
        print "%s failed"%cmd
        print traceback.format_exc()

    #print out
    #print err
    return out,err

it lists like

Only in /Users/username/FWIntegration/branch_4355c1/.git/refs/tags: DIN2944T146R6_REL_9_74_5 
Only in /Users/username/FWIntegration/branch_4355c1/.git/refs/tags: DIN2944T18R2_REL_9_48_1 
Only in /Users/username/FWIntegration/branch_4355c1/.git/refs/tags: DIN2944T51R2_REL_9_55_2

1 Answer 1

1

The problem is due to the quotes you have in the cmd string. You're not processing the command with a shell, you're using cmd.split() to parse it, so those quotes are being sent literally to the program.

Use a shell so everything will be parsed properly:

proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.