how do you know the bat file is not working? Are you testing the results of
what the bat file executed to know this? You cannot run the application and
look for a bat file window. If you insist that the bat file is not firing
off, here is another way to invoke it using the command line modifying your
code.
System.Diagnostics.Process p = new Process();
// p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.RedirectStandardInput=true;
p.StartInfo.FileName = @"cmd"; //"C:\\ftp_scripts\\script.bat";
// p.StartInfo.UseShellExecute=true;
p.StartInfo.UseShellExecute=false;
p.Start();
// p.WaitForExit();
// p.Dispose();
StreamWriter sIn = myProcess.StandardInput;
sIn.AutoFlush = true;
StreamReader sOut = myProcess.StandardOutput;
sIn.Write(@"C:\ftp_scripts\script.bat" + System.Environment.NewLine);
sIn.Close();
string results = sOut.ReadToEnd().Trim();
p.Close();
The results of the script, whether it failed to run or errored out will be
contained in results variable so you can know exactly what is going on.
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
<danl@drawnet_no_spam.com> wrote in message
news:21**********************************@microsof t.com...
I need to be able to execute a .bat file from a C# web application.
I have the following code that compliles and seems to run fine, but the
bat file never does it's work.
====================================
System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName = "C:\\ftp_scripts\\script.bat";
p.StartInfo.UseShellExecute=true;
p.Start();
p.WaitForExit();
p.Dispose();
=====================================
The bat file works fine when i don't call it from the web app.
What could be wrong?
Is it a permissions thing?
Why am I not getting any errors?
How do I get errors back to my calling code?
Any help would be greatly appreciated.
-Dan