Thursday, March 22, 2007

Brendan Tompkins : Run a .BAT file from ASP.NET

Brendan Tompkins : Run a .BAT file from ASP.NET: "Run a .BAT file from ASP.NET
Okay, running .BAT files from ASP.NET using the System.Diagnostics.Process object and static methods this should be easy, right? Well, this might work for you, but it certainly won't work on my machines. And after doing lots of reasearh on the issue, it seems that other people are also having problems with this too.
I wrestled with permissions and all sorts of other stuff, trying to get a simple batch file to run, with no luck. I tried lauching the bat file directly, launching cmd.exe and calling the bat file using stin. No dice. It seems that something on my machine was keeping an unattended process from running bat files. This makes sense, but I was never able to pinpoint what was preventing this, so I came up with a workaround.
I realized that since I could sucessfully run cmd.exe, and send commands to it via stin, I could just open the batch file, and send each line to cmd.exe, which is essentially the same as running a batch file itself. This technique works great, and I thought I'd pass along the code here."

No comments: