0

I have an odd problem I can't seem to diagnose.

I'm calling am external binary, waiting for it to complete and then passing back a result based on standard out. I also want to log error out.

I wrote this and it works a treat in 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);
            }
        }


    }
}

So I install it on a Windows Server 2008 box and the NetOutputDataHandler and NetErrorDataHandler handlers are never called.

The app is compiled for .NET v4.

Any ideas what I'm doing wrong?

Ed Lewis
  • 43
  • 1
  • 3

1 Answers1

0

You might want to inspect the code access security policy. You may start by runing the caspol.exe with the -l parameter(s) of the caspol.exe for the -u[ser] running the app.

Don't forget to check if you still encounter the same issue when running the app as Administrator

  • Thanks, I'm running as Administrator and the same problem occurs. Strangely if I use the non async standard out (e.g. ReadToEnd()) the problem doesn't occur but I can't capture Std and Err streams that way – Ed Lewis Sep 11 '12 at 20:00