2

I am writing a small utility to execute svn commands using c# program

Here is the key line in my program

System.Diagnostics.Process.Start("CMD.exe", @"svn checkout C:\TestBuildDevelopment\Code");

As I assume, the above code should be able to do svn check out and download all the code to the local path mentioned above. But what's happening is that, the command prompt opens up with the default path of the c# project and does nothing.

If I run this svn command in command line it works fine. But when I run using C# it just pops up the command prompt without executing the svn checkout operation. Any idea on what is going wrong?

3
  • 4
    Have you considered using svnsharp instead? Commented Aug 28, 2012 at 6:11
  • @JonSkeet svnsharp is great!!! I downloaded the dll and good to go now. Thanks a lot. I should mark this as the best answer. Eventhough there are some acceptable answers below, this is the best answer. But how can I mark this as accepted. Commented Aug 28, 2012 at 13:39
  • This is very old... nowadays, there is also SharpSVN: sharpsvn.open.collab.net Commented Oct 30, 2017 at 19:35

3 Answers 3

9

You don t have to run CMD.exe. CMD.exe ist just a program that calls other assemblies. You can call svn.exe directly with your argument checkout ... (but isnt there a url missing?)

Process.Start("svn.exe", @"checkout C:\TestBuildDevelopment\Code");

you may also try this:

Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.RedirectStandardOutput = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "svn.exe";
startInfo.CreateNoWindow = true;
startInfo.Arguments = "checkout ...";

proc.StartInfo = startInfo;
if(proc.Start()) {
    proc.WaitForExit();
}
Sign up to request clarification or add additional context in comments.

Comments

4

You need to add the parameter /c. Try:

Process.Start("CMD.exe", @"/c svn checkout C:\TestBuildDevelopment\Code");

The parameter /c means that the cmd should execute the command and exit.

Comments

1

As Jon notes, svnsharp would be a good choice here; but IMO the problem is shelling cmd.exe, rather than the exe you actually want to run:

Process.Start(@"path\to\svn.exe", @"checkout ""C:\TestBuildDevelopment\Code""");

although a ProcessStartInfo would make it easier to set the working path etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.