Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
Do you want to read the output directly from c# or create the SvnDiff.xml file? –  Julián Urbano Mar 28 '13 at 22:53
    
I want to create SvnDiff.xml file –  Zabaa Mar 28 '13 at 22:55

4 Answers 4

up vote 0 down vote accepted

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);

share|improve this answer
    
Thanks you to :) I use StandardOutput and it work to. –  Zabaa Mar 28 '13 at 23:16

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();
share|improve this answer

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

share|improve this answer
    
It working with /C. Thank you very much :) –  Zabaa Mar 28 '13 at 23:02
    
What are the /K and /C for? –  Julián Urbano Mar 28 '13 at 23:05
    
@caerolus open a command prompt and type CMD /? to get help on command shell switches. –  Steve Mar 28 '13 at 23:07
    
oh, didn't notice you actually executed cmd! –  Julián Urbano Mar 28 '13 at 23:10

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.