3

Hi i have a problem using svn command in code behind :

public void SvnDiff(int rev1, int rev2)
        {
            try
            {
                var p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "svn";
                string arg = string.Format("diff -r {0}:{1} --summarize --xml > SvnDiff.xml", rev1, rev2);
                Console.WriteLine(arg);
                p.StartInfo.Arguments = arg;
                p.Start();
                p.WaitForExit();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

When i use this command in cmd, it's working fine. svn diff -r 2882:2888 --summarize --xml > SvnDiff.xml

but when i run my method i got this message: svn: E020024: Error resolving case of '>'

What can i do right now to solve this ? Thanks for any advice

2
  • Do you want to read the output directly from c# or create the SvnDiff.xml file? Commented Mar 28, 2013 at 22:53
  • I want to create SvnDiff.xml file Commented Mar 28, 2013 at 22:55

4 Answers 4

1

You can read all text and then write to the file as @Scott suggested, but it can be problematic if the output is too large.

You can instead write as the output is generated. Create a local StreamWriter for the file, and a method to write whenever new output data is available:

StreamWriter redirectStream = new StreamWriter("SvnDiff.xml")

void Redirect(object Sender, DataReceivedEventArgs e)
{
  if ((e.Data != null)&&(redirectStream != null))
    redirectStream.WriteLine(e.Data);
}

and when you start the process:

p.OutputDataReceived += new DataReceivedEventHandler(Redirect); // handler here to redirect
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();

redirectStream.Flush();
redirectStream.Close();
0
0

The > SvnDiff.xml part of your command line aren't arguments being passed to SVN. They're redirecting standard output. To do that, take a look at the documentation:

Since you already have RedirectStandardOutput set properly, you just need to take advantage of it. Simply put

string output = p.StandardOutput.ReadToEnd();

in front of your p.WaitForExit(); line.

Then, just use File.WriteAllText("SvnDiff.xml", output);

0
0

Try with this....

var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
string arg = string.Format("/K svn diff -r {0}:{1} --summarize --xml > SvnDiff.xml", rev1, rev2);
Console.WriteLine(arg);
p.StartInfo.Arguments = arg;
p.Start();
p.WaitForExit();

if it works then change /K with /C

3
  • What are the /K and /C for? Commented Mar 28, 2013 at 23:05
  • @caerolus open a command prompt and type CMD /? to get help on command shell switches. Commented Mar 28, 2013 at 23:07
  • oh, didn't notice you actually executed cmd! Commented Mar 28, 2013 at 23:10
0

Thanks for answers, I use StandardOutput and it work :)

var p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "svn";
                p.StartInfo.Arguments = string.Format("diff -r {0}:{1} --summarize --xml", rev1, rev2);
                p.Start();
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                File.WriteAllText("SvnDiff.xml", output);

Thanks for all of you.

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.