微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c#-将svn的输出读入字符串

好的,所以在我将SSH SSH到服务器并使用svn命令行客户端而不是远程桌面的想法之后(我的想法并不多,tbh),我和我的老板决定了,如果我们可以从Windows Server 2003更新每个项目,那就更好了.单个本地网页(仅适用于我们的开发服务器).
现在,我确实使它可以工作(一次),但是通常没有.

我正在使用以下代码:


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

从理论上讲,这应该从svn应用程序中收集输出,并将其写入页面,但是不会(除非在极少数情况下实际更新,但是当我特别需要输出时,不是这样!)

谁能发现问题?

解决方法:

这是一些我的应用程序中的代码-基本上只是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()
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐