0

診断できない奇妙な問題があります。

外部バイナリを呼び出し、完了するのを待ってから、標準出力に基づいて結果を返します。また、エラーをログアウトしたい。

私はこれを書きました、そしてそれはWindows 7で扱います

namespace MyApp
{
    class MyClass
    {

        public static int TIMEOUT = 600000;
        private StringBuilder netOutput = null;
        private StringBuilder netError = null;

        public ResultClass runProcess()
        {

            using (Process process = new Process())
            {
                process.StartInfo.FileName = ConfigurationManager.AppSettings["ExeLocation"];
                process.StartInfo.WorkingDirectory = Path.GetDirectoryName(ConfigurationManager.AppSettings["ExeLocation"]);

                process.StartInfo.UseShellExecute = false;

                process.StartInfo.RedirectStandardOutput = true;
                process.OutputDataReceived += new DataReceivedEventHandler(NetOutputDataHandler);
                netOutput = new StringBuilder();

                process.StartInfo.RedirectStandardError = true;
                process.ErrorDataReceived += new DataReceivedEventHandler(NetErrorDataHandler);
                netError = new StringBuilder();

                process.Start();

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();


                if (process.WaitForExit(TIMEOUT))
                {
                    // Process completed handle result
                    //return my ResultClass object
                }
                else
                {
                    //timed out throw exception
                }
            }


        }

        private void NetOutputDataHandler(object sendingProcess,
              DataReceivedEventArgs outLine)
        {
            //this is being called in Windows 7 but never in Windows Server 2008
            if (!String.IsNullOrEmpty(outLine.Data))
            {
                netOutput.Append(outLine.Data);
            }
        }

        private void NetErrorDataHandler(object sendingProcess,
            DataReceivedEventArgs outLine)
        {
            //this is being called in Windows 7 but never in Windows Server 2008
            if (!String.IsNullOrEmpty(outLine.Data))
            {
                netError.Append(outLine.Data);
            }
        }


    }
}

そのため、Windows Server 2008 ボックスにインストールすると、NetOutputDataHandler および NetErrorDataHandler ハンドラーは呼び出されません。

アプリは .NET v4 用にコンパイルされています。

私が間違っていることはありますか?

4

1 に答える 1

0

コードアクセスセキュリティポリシーを確認することをお勧めします。アプリを実行している-u[ser]のcaspol.exeの-lパラメーターを指定してcaspol.exeを実行することから始めることができます。

管理者としてアプリを実行しているときに同じ問題が引き続き発生するかどうかを確認することを忘れないでください

于 2012-09-11T19:18:40.837 に答える