开发者

call batch by web service in .net

I have a batch script that takes as a pa开发者_如何学运维rameter the source to an image and outputs the image modified. Can I place the batch on a server and call it by means of a webservice?


To get you started, here is some information and pointers to different alternatives. Try them and see which one more closely solves your requirements and work for you.

The simplest, just invoke Process.Start() passing the full filespec to the batch file

Process.Start("c:\bats\test.bat")

If you need more control, you might create a Process.StartInfo and pass it to the Process.Start method. I have not tested this code.

Process p= new Process();
p.StartInfo.WorkingDirectory = "C:\temp";
p.StartInfo.FileName = "c:\bats\test.bat";
p.StartInfo.Arguments =  "arguments";
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();

A little bit more convoluted way is running a CMD and sending commands to it. See this article http://codebetter.com/brendantompkins/2004/05/13/run-a-bat-file-from-asp-net/ However, this is a pretty rough and brute force batch execution, that may not work for all BAT files (for example those that have FOR commands with %% variables) and have some side effects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜