Issue in Batch execution at Server side
Hi,
I have a requirement to execute a batch at server side. This batch creates some files in the server. When ever I am running the following code, I am not getting any output of created files and more over command window is not opened in server .
System.Diagnostics.Process myprocess = new System.Diagnostics.Process(); // Declare New Process
System.Diagnostics.ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo();
lObjProcInfo.UseShellExecute = false;
lObjProcInfo.RedirectStandardOutput = true;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.RedirectStandardInput = true;
lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.FileName = lStrBatchPath;
myprocess = System.Diagnostics.Process.Start(lObjProcInfo);
Please help out.
Thanks
Sreenath
Sreenath GVPosted Apr 11, 2012, 2:53 AM
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....
revised code...
System.Diagnostics.
lObjProcInfo.UseShellExecute =
lObjProcInfo.CreateNoWindow =
lObjProcInfo.RedirectStandardOutput =
lObjProcInfo.RedirectStandardInput =
lObjProcInfo.RedirectStandardError =
lObjProcInfo.WindowStyle =
lObjProcInfo.FileName = lStrBatchPath;
System.Diagnostics.
ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo();false;true;true;true;true;ProcessWindowStyle.Normal;Process myprocess = new System.Diagnostics.Process(); // Declare New Processmyprocess.EnableRaisingEvents =
myprocess.OutputDataReceived +=
myprocess.ErrorDataReceived +=
myprocess.Exited +=
myprocess.StartInfo = lObjProcInfo;
myprocess.Start();
myprocess.BeginOutputReadLine();
myprocess.BeginErrorReadLine();
myprocess.WaitForExit();
true;new System.Diagnostics.DataReceivedEventHandler(myprocess_OutputDataReceived);new DataReceivedEventHandler(myprocess_ErrorDataReceived);new EventHandler(myprocess_Exited);--------------------------------------------
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());Sam HobbsPosted Apr 10, 2012, 3:48 PM
For testing purposes take out (comment out) the lines (there are two of them) that set CreateNoWindow to true so you can see the window to determine if there is an error shown.
Your code sets RedirectStandardOutput and RedirectStandardInput to true. Ensure that you have code to write the input and read the output.