Due to a terrible chain of events I had to reinstall part of my software. Git among it, but a newer version.

Something changed because earlier all four evaluations were giving me a version info:

gitPath = "\"C:\\Program Files\\Git\\cmd\\git.exe\"";
(*it is also on PATH*)
Import["!git -C \"C:\\Users\" --version", "Text"] (*using PATH, escaped*)

"git version 2.9.0.windows.1"

Import["!git -C C:\\Users --version", "Text"] (*using Path, not escaped so not general*)

"git version 2.9.0.windows.1"

Import["!" <> gitPath <> " -C \"C:\\Users\" --version", "Text"] 


Import["!" <> gitPath <> " -C C:\\Users --version", "Text"] 

"git version 2.9.0.windows.1"

This basically means that calling git from Mthematica (via Import) is impossible unless you have it on PATH.

Which is an acceptable solution but I would like to understand what is the problem, the more that the third command works from a terminal:

enter image description here

  • 1
    $\begingroup$ Try RunProcess. It did have several annoying issued in 10.x on Windows, but those might already (hopefully!) be fixed in 10.4. You must specify the executable path and the arguments separately with RunProcess. You can also set a working directory for the process. $\endgroup$ – Szabolcs Jul 4 '16 at 12:03
  • $\begingroup$ @Szabolcs RunProcess[{ "C:\\Program Files\\Git\\cmd\\git.exe", "-C", "C:\\Program Files", "version" }] seems to work, thanks, I tried once but wasn't motivated enough to check what should be escaped, what not, should I use $SystemShell etc etc. $\endgroup$ – Kuba Jul 4 '16 at 12:17
  • 1
    $\begingroup$ I don't have Git and hence can't test but I think the issue should be the same as with Run. Please try my wrapByQuotes function from the second section of this answer in the same way as I used it for gifsicle. Also you can be interested in the post by Rui Liu (Wolfram Technical Support) linked there. $\endgroup$ – Alexey Popkov Jul 4 '16 at 13:24
  • $\begingroup$ @AlexeyPopkov Thanks, a lot of reading, I will take a look as soon as motivation and free time positively interfere. $\endgroup$ – Kuba Jul 4 '16 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.