-1

I have a winforms application, and I'm trying to run a git fetch command using a Process. I need to know if the git fetch was successfully/ not and show it on the UI. I wanted to know if there is a way I can get the status if git action was successful by the Process.

Thanks!

pradeepradyumna
  • 952
  • 13
  • 34
  • Possible duplicate of [How to know when a process created by Process.Start() was closed?](https://stackoverflow.com/questions/10920964/how-to-know-when-a-process-created-by-process-start-was-closed) – O. Jones Aug 26 '17 at 15:32
  • Just as a side note: unless you really don't need it, consider using a proper C# Git wrapper library like [libgit2sharp](https://github.com/libgit2/libgit2sharp). In particular, [this wiki page](https://github.com/libgit2/libgit2sharp/wiki/git-fetch) may be helpful. – Felipe Aug 26 '17 at 17:40
  • 2
    Possible duplicate of [Get return value from process](https://stackoverflow.com/questions/1585354/get-return-value-from-process) – phd Aug 26 '17 at 19:04

1 Answers1

1

You should look for exit code to get the result and read std out to get messages. Zero stands for success and non-zero for error. It's a standard for the majority of console apps.

Checked out with powershell quickly. Git sticks to this rule.enter image description here

Eduard Lepner
  • 639
  • 6
  • 17
  • I liked it, and since you've run powershell,if you've seen it also returns 'Already up to date' message when a repo. is up to date. So I'm curious to know, if there is anyway that I can get this message and would like to show in the UI. – pradeepradyumna Aug 26 '17 at 15:47
  • Updated the answer. Thanks to @DiskCrasher – Eduard Lepner Aug 26 '17 at 16:15
  • I have created a class library, [commander](https://www.nuget.org/packages/Commander/2017.4.19.1919-beta), currently in a pre-release state because I don't like the package setup. You can check out the code on [github](https://github.com/lassevk/commander), this contains classes and helpers to easily help you catch the output of a program. Though, it's not that hard and you'll find quite a few questions and answers here on Stack Overflow on how to capture console output. – Lasse V. Karlsen Aug 26 '17 at 16:25