简体   繁体   中英

Why this Git pull from C# code doesn't work

I have to pull updates from C# code but it doesn't pull the updates. I tried the command line and it worked fine.

    string gitCmd = "/C cd 'C:\\Users\\jean.wang\\source\\repos\\UpdateScriptRename\\vcs\\trunk' && git pull";
        Process.Start("CMD.exe", gitCmd);

Your string has '' in cd, but cmd doesn't accept the '' as enquoting character, change them to "" , like so:

"/C cd \"C:\\Users\\jean.wang\\source\\repos\\UpdateScriptRename\\vcs\\trunk\" && git pull";

or you can even just set working directory before Process.Start:

string dir = "C:\\Users\\jean.wang\\source\\repos\\UpdateScriptRename\\vcs\\trun";
Process.Start(new ProcessStartInfo(){FileName = "git.exe", Arguments = "pull", WorkingDirectory = dir});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM