How to run git commands through MATLAB script?

Issue

I am trying to run git command through matlab script and get the terminal output.
I have had success when running

[status,cmdoutput] =  system('TERM=ansi git diff-tree -r --name-only asdasd asdasdas');

However if I use git diff instead of git diff-tree, I get empty result back. I have tried to run the same command on terminal which runs fine.

OS : Ubuntu 18.04
MATLAB R2020b

Any help is appreciated 🙂

Solution

It might be related to the pager. I’ve been using the following code without problem on Ubuntu 20.04

[~, cmdoutput] = system('git --no-pager diff --no-color');

Answered By – X Zhang

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published