0

ncftpput.exe から出力ストリームを取得し、ストリームを非同期的に操作できるようにしようとしています。ncftpput.exe は、ストリームを行ごとに出力するのではなく、同じ行を新しい情報で更新し続けるだけです (これは関連する可能性があります)。断続的に機能します-情報が返される場合と返されない場合があります。

基本的に、より安全で定期的な方法でリダイレクトされるように、回線を頻繁に更新するストリームを取得する方法はありますか?

これが私がこれまでに得たものです(無関係な無関係な情報を取り除くために注釈を付けましたが、これが本質です):

class Program
{
    static int main()
    {
        internal Process m_Tool { get; set; }
        internal ProcessStartInfo m_StartInfo { get; set; }
        internal static string m_StandardData { get; set; }
        internal static string m_ErrorData { get; set; }

        m_Tool = new Process();
        m_StartInfo = new ProcessStartInfo();
        m_StartInfo.FileName = @"C:\utils\ncftpput.exe";
        m_StartInfo.UseShellExecute = false;
        m_StartInfo.RedirectStandardOutput = true;
        m_StartInfo.RedirectStandardError = true;
        m_StandardData = "";
        m_ErrorData = "";
        m_StartInfo.Arguments = /* Various starting args */
        m_Tool.StartInfo = m_StartInfo;
        m_Tool.Start();

        string standardLine;
        string errorLine;

        try
        {
            m_Tool.OutputDataReceived += ProcessStandardDataHandler;
            m_Tool.ErrorDataReceived += ProcessErrorDataHandler;

            m_Tool.BeginErrorReadLine();
            m_Tool.BeginOutputReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        while (!m_Tool.HasExited)
        {
            System.Threading.Thread.Sleep(5000);
            standardLine = m_StandardData;
            errorLine = m_ErrorData;
        } 
    }
    private static void ProcessErrorDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {

        if (!String.IsNullOrEmpty(outLine.Data))
        {
            // Add the text to the collected output.
            m_ErrorData = outLine.Data.ToString();
            m_DataReceived = true;

        }
    }

    private static void ProcessStandardDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {

        if (!String.IsNullOrEmpty(outLine.Data))
        {
            // Add the text to the collected output.
            m_StandardData = outLine.Data.ToString();
        }
    }
}

前もって感謝します!!

4

1 に答える 1

0

最終的に、ncftpput.exe がコンソールに出力する方法が原因で、リダイレクトされた出力から十分な情報を取得できないことがわかりました。そこで私は、独自の FTP アプリケーションを作成して使用することにしました。これは ncftpput.exe よりも単純なアプリケーションですが、必要なことは実行してくれます。標準の .NET ライブラリを使用しましたが、特別なことは何もありません。

于 2013-08-08T10:53:15.273 に答える