I am using below function to call EAR_Encrypt_FTP.bat in C#. Is there any way to trace the echo messages dispayed in cmd.exe while running the batch file??
I need to process echo messages displayed on command prompt screen log the process.
private static short batchfileInvoke(string ftpFileName, string headerFile)
{
short value = 0;
Process p = null;
try
{
p = new Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
string argument1 = "EAR_Encrypt_FTP.bat";
string test = "\"" + ftpFileName + "\"";
string argument2 = test;
string test1 = "\"" + headerFile + "\"";
string argument3 = test1;
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(argument1);
startInfo.Arguments = "/C EAREncryptFTP.bat " + argument2 + " " + argument3;
p.StartInfo = startInfo;
p.Start();
p.WaitForExit();
int value2 = p.ExitCode;
value = (short)value2;
if(value==0)
{
Console.WriteLine("Encryption process is done");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}",
ex.Message, ex.StackTrace.ToString());
value = -4;
}
return value;
}