System.Diagnostic.Process不返回从应用程序抛出的异常

时间:2014-07-03 08:55:27

标签: c#

我使用SSMAforAccessConsole32.exe将Access DB迁移到SQL DB。因为我需要拨打exe。我使用Process exeProcess = Process.Start(objPSI)来启动这个过程。当SSMAforAccessConsole32.exe抛出一些异常时,它不会返回异常。

需要帮助才能获得exe引发的异常。任何帮助将不胜感激。

请在下面找到代码。

ProcessStartInfo objPSI = new ProcessStartInfo();
objPSI.Arguments = "-s " + '"' + strDir + "AssessmentReportGenerationSample.xml" + '"' + " -c " + '"' + strDir + "ServersConnectionFileSample.xml" + '"' + " -v " + '"' + strDir + strVariableFile + '"';
//objPSI.Arguments = "-s " + '"' + strDir + "AssessmentReportGenerationSample.xml" + '"' + " -c " + '"' + strDir + "ServersConnectionFileSample.xml" + '"' + " -v " + '"' + strDir + "VariableValueFileSample.xml" + '"';
objPSI.FileName = strDIR1 + "SSMAforAccessConsole32.exe";
objPSI.CreateNoWindow = true;
objPSI.UseShellExecute = false;                    
objPSI.RedirectStandardError = true;
try
{
    using (Process exeProcess = Process.Start(objPSI))
    {

        string error = exeProcess.StandardError.ReadToEnd();
        //  string strError = SSMAError.ExceptionResult.Propagate.ToString();                            
        //exeProcess.

        exeProcess.WaitForExit();                               
    }
}                 
catch (Exception ex)
{
     MessageBox.Show(ex.Message);
     // Log error.
}

0 个答案:

没有答案