Reading output from svn to string

Well, that’s why, after I submitted SSHing to the server and used the svn command-line client instead of remote desktop (not much tbh idea), my boss and I decided that it would be better if we could update each project from one local web pages (this is only for our development server). Now, I got it to work (once), however it often does not.

I am using the following code:


        ProcessStartInfo start = new ProcessStartInfo("C:\Program Files (x86)\CollabNet\Subversion Client\svn.exe", "update " + UpdatePath);
        start.RedirectStandardOutput = true;
        start.UseShellExecute = false;
        start.ErrorDialog = false;
        start.CreateNoWindow = true;
        start.WindowStyle = ProcessWindowStyle.Hidden;
        Process process = Process.Start(start);
        StreamReader output = process.StandardOutput;
        string text = output.ReadToEnd();
        process.WaitForExit();
        Response.Write(text + "<br />" + UpdatePath);

in theory, this should collect the output from the svn application and write it to the page, however it is not (if only in the rare case when it is really updated, however it is not so when I especially need a way out!)

Can anyone spot the problem?

+3
5

, - MSDN. (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.outputdatareceived.aspx)

private void SvnOutputHandler(object sendingProcess,
                                      DataReceivedEventArgs outLine)
{
    Process p = sendingProcess as Process;

    // Save the output lines here
}


private void RunSVNCommand()
{
    ProcessStartInfo psi = new ProcessStartInfo("svn.exe",
                                                string.Format("update \"{0}\" {1}", parm1, parm2));

    psi.UseShellExecute = false;
    psi.CreateNoWindow = true;

    // Redirect the standard output of the sort command.  
    // This stream is read asynchronously using an event handler.
    psi.RedirectStandardOutput = true;
    psi.RedirectStandardError = true;

    Process p = new Process();

    // Set our event handler to asynchronously read the sort output.
    p.OutputDataReceived += SvnOutputHandler;
    p.ErrorDataReceived += SvnOutputHandler;
    p.StartInfo = psi;

    p.Start();

    p.BeginOutputReadLine();
    p.BeginErrorReadLine();

    p.WaitForExit()
}
+2

, SharpSvn (http://sharpsvn.open.collab.net). API, .

svn, , , .

+2

,

StreamReader output = process.StandardOutput;
string text = output.ReadToEnd();

WaitToExit()

, - , , , .

, string text= process.StandardOutput.ReadToEnd();

0

. , , Windows , , . , WaitForExit(), .

, .NET, . , .

0

. -, .

- , :

using CSharpTest.Net.Processes;
    static void Update(string sourcePath, Action<string> output)
    {
        ProcessRunner run = new ProcessRunner("svn.exe", "update", "{0}");
        run.OutputReceived +=
            delegate(Object o, ProcessOutputEventArgs e) { output(e.Data); };
        int exitCode = run.RunFormatArgs(sourcePath);
        if (exitCode != 0)
            throw new ApplicationException(
                String.Format("SVN.exe returned {0}.", exitCode)
                );
    }
0
source

Source: https://habr.com/ru/post/1719544/


All Articles