Getting git fetch output to file through python -


i trying save git fetch output file through python, using:

subprocess.check_output(["git", "fetch", "origin", ">>", "c:/bitbucket_backup/backup.log", "2>&1"], cwd='c:/bitbucket_backup/loopx') 

but believe there missing in subprocess.check_output args because when adding >> c:/bitbucket_backup/backup.log 2>&1 receive error:

traceback (most recent call last):   file "<pyshell#28>", line 1, in <module>      subprocess.check_output(["git", "fetch", "origin", ">>", "c://bitbucket_backup//backup.log", "2>&1"], cwd='c://bitbucket_backup//loopx')   file "c:\users\fabio\appdata\local\programs\python\python36-32\lib\subprocess.py", line 336, in check_output      **kwargs).stdout   file "c:\users\fabio\appdata\local\programs\python\python36-32\lib\subprocess.py", line 418, in run      output=stdout, stderr=stderr) subprocess.calledprocesserror: command '['git', 'fetch', 'origin', '>>', 'c://bitbucket_backup//backup.log', '2>&1']' returned non-zero exit status 128. 

quickfix: enable shell features handle redirection arguments:

subprocess.check_output(["git", "fetch", "origin", ">>", "c:/bitbucket_backup/backup.log", "2>&1"], cwd='c:/bitbucket_backup/loopx', shell=true) 

but that's dirty python able nicely:

output = subprocess.check_output(["git", "fetch", "origin"], stderr=subprocess.stdout, cwd='c:/bitbucket_backup/loopx') open("c:/bitbucket_backup/backup.log","ab") f:  # append file     f.write(output) 

that said, if you're rewrite git commands in python, maybe should use git python api gitpython instance.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -