1

tf.exe に独自の UI を提供するアプリケーションを作成しようとしています (TFS 2010)。(はい、VS が既にこれを行っていることは知っていますが、このアプリはカスタムです)。プロパティなどの一部のコマンドでは、stdout から出力を取得したいと考えています。また、コマンドが失敗したときに、stderr からエラー出力を取得したいと考えています。次のように、.NET の Process クラスを使用して tf.exe を起動しています。

try
{
   sccProcess.StartInfo.FileName = "tf.exe"; 
   sccProcess.StartInfo.Arguments = arguments;
   sccProcess.StartInfo.CreateNoWindow = true;
   sccProcess.StartInfo.UseShellExecute = false;
   sccProcess.StartInfo.RedirectStandardOutput = true;
   sccProcess.StartInfo.RedirectStandardError = true;
   sccProcess.Start();

   output = sccProcess.StandardOutput.ReadToEnd();

   // Redirecting synchronously from output and error streams may cause a deadlock.
   // To prevent that, we always read the error stream asynchronously.
   sccProcess.ErrorDataReceived += (sender, args) => errorStringBuilder.Append(args.Data);
   sccProcess.BeginErrorReadLine();

   sccProcess.WaitForExit();
   exitCode = sccProcess.ExitCode;

   error = errorStringBuilder.ToString();
}
catch (Win32Exception)
{
    // The file name for the process couldn't be found.
    exitCode = -1;
}
finally
{
    sccProcess.Close();
}

ただし、「tf checkin」などのコマンドを実行すると、標準エラーがリダイレクトされると、通常開いているチェックイン ダイアログ ボックスが表示されなくなっていることに気付きます。代わりに、チェックインが行われます。したがって、tf.exe の stderr をリダイレクトすると、noprompt フラグを設定したかのように動作するようです。tf.exe ダイアログ プロンプトを停止せずに stderr データをキャプチャする方法を知っている人はいますか?

ありがとう、

-クレイグ

4

2 に答える 2

2

コードから tf.exe を呼び出すよりも、 TFS APIを直接呼び出す方がよい場合があります。そうすれば、アプリケーションの動作をより詳細に制御でき、stderr ではなく例外のすべての利点を利用できます。この API は、tf.exe tfpt.exe および Visual Studio から利用できるよりも多くの機能も公開します。

于 2012-02-05T15:35:09.093 に答える