Executing BatchFile from C# Program
<p>I am writing the batch file and executing it through c# program. </p>

<p><strong>Writing Batch file :</strong> </p>

<p>I will get the Path, Executable name and arguments from app.config and write them to a batch file.</p>

<p><strong>Executing Batch file :</strong> </p>

<p>Once i write the batch file i pass the file name to below function which executes the batch file to launches an application.</p>

<p><strong>Problem :</strong></p>

<p>My program will write a lot of batch files which are executed immediately after each and every file is written. I find that, some times the applications are not started which means that batch files are not executed. I dint even get any error messages or prompts for this failure of batch file execution.  </p>

<p><strong>Expected solution :</strong></p>

<p>Any problem in executing the batch file, i should be able to log it or prompt an error.</p>

<p><strong>Code that executes Batch File :</strong> </p>

<pre><code>            System.Diagnostics.ProcessStartInfo procinfo = new System.Diagnostics.ProcessStartInfo("cmd.exe");
            procinfo.UseShellExecute = false;
            procinfo.RedirectStandardError = true;
            procinfo.RedirectStandardInput = true;
            procinfo.RedirectStandardOutput = true;

            System.Diagnostics.Process process = System.Diagnostics.Process.Start(procinfo);

            System.IO.StreamReader stream = System.IO.File.OpenText(BatchPath + LatestFileName);
            System.IO.StreamReader sroutput = process.StandardOutput;
            System.IO.StreamWriter srinput = process.StandardInput;

            while (stream.Peek() != -1)
            {
                srinput.WriteLine(stream.ReadLine()); 
            }

            Log.Flow_writeToLogFile("Executed .Bat file : " + LatestFileName);
            stream.Close();
            process.Close();
            srinput.Close();
            sroutput.Close();
</code></pre>

<p><em><strong>Very urgent..Help !!!</em></strong></p>
