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.Diagnost ics.Process p = new Process();
// p.StartInfo.Red irectStandardOu tput=false;
p.StartInfo.Red irectStandardOu tput=true;
p.StartInfo.Red irectStandardIn put=true;
p.StartInfo.Fil eName = @"cmd"; //"C:\\ftp_script s\\script.bat";
// p.StartInfo.Use ShellExecute=tr ue;
p.StartInfo.Use ShellExecute=fa lse;
p.Start();
// p.WaitForExit() ;
// p.Dispose();
StreamWriter sIn = myProcess.Stand ardInput;
sIn.AutoFlush = true;
StreamReader sOut = myProcess.Stand ardOutput;
sIn.Write(@"C:\ ftp_scripts\scr ipt.bat" + System.Environm ent.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_n o_spam.com> wrote in message
news:21******** *************** ***********@mic rosoft.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.Diagnost ics.Process p = new Process();
p.StartInfo.Red irectStandardOu tput=false;
p.StartInfo.Fil eName = "C:\\ftp_script s\\script.bat";
p.StartInfo.Use ShellExecute=tr ue;
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