Skip to content
Advertisement

Git commands output in a file using python in Windows 10

I am trying

git status *> test.txt 

This works in powershell well but if I do this using python –

os.system('git status'+' *> '+log_path+'git_output.txt')

fatal: ‘*’ does not appear to be a git repository fatal: Could not read from remote repository.

os.system('git status'+' 2> '+log_path+'git_output.txt')

Btw, this worked! But I want all kinds of output in the file!

What is the best way to do this?

Advertisement

Answer

Have a look at redirection from command prompt (different from powershell)

os.system('git status'+' 1> '+log_path+'git_output.txt 2>&1')
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement