Hi,
I tried to log output of the batch file run. noticed that after running batch file it directly eneterd into myprocess_Exited event with out any myprocess_OutputDataReceived or myprocess_ErrorDataReceived.
It seems when running batch, actually batch is not been executed...but batch is running on server properly on manual execution
any help over here plzz....
System.Diagnostics.ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo();
lObjProcInfo.UseShellExecute = false;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.RedirectStandardOutput = true;
lObjProcInfo.RedirectStandardInput = true;
lObjProcInfo.RedirectStandardError = true;
lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal;
lObjProcInfo.FileName = lStrBatchPath;
System.Diagnostics.Process myprocess = new System.Diagnostics.Process(); // Declare New Process
myprocess.EnableRaisingEvents = true;
myprocess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(myprocess_OutputDataReceived);
myprocess.ErrorDataReceived += new DataReceivedEventHandler(myprocess_ErrorDataReceived);
myprocess.Exited += new EventHandler(myprocess_Exited);
myprocess.StartInfo = lObjProcInfo;
myprocess.Start();
myprocess.BeginOutputReadLine();
myprocess.BeginErrorReadLine();
myprocess.WaitForExit();
-------------------------------------
public void myprocess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
try
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.INFORMATION, e.Data);
}
catch (Exception ex)
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
}
}
public void myprocess_Exited(object sender, EventArgs e)
{
try
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.INFORMATION, "Exited (Event) - Batch execution completed");
}
catch (Exception ex)
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
}
}
public void myprocess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
try
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, e.Data);
}
catch (Exception ex)
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
}
}