Home > Software engineering >  Store git command result into a variable using MATLAB script
Store git command result into a variable using MATLAB script

Time:11-10

I'm trying to get the result after executing the git command function !git config --global user.name which outputs my username in the command prompt of my MATLAB.

Now if I assign the same to a variable to use it in another instance I'm getting the below error as shown below.

userName = !git config --global user.name

Error : Parse error at !git config --global user.name : Usage might be invalid MATLAB syntax

disp(userName);

CodePudding user response:

You will need something like

[~, out.git_hash] = system('git rev-parse --verify HEAD');
[~, out.git_status] = system('git --no-pager diff --no-color');

etc.

On Windows, depending on different options during setup, you may need to supply the full path to the git binary, e.g.

[~, out.git_hash] = system('"C:/Program Files/Git/mingw64/bin/git"  rev-parse --verify HEAD'); 
[~, out.git_status] = system('"C:/Program Files/Git/mingw64/bin/git" --no-pager diff --no-color'); 

Just be cautious with pager-related parameters.

  • Related