C # Batch Call Method _c# Tutorial

Source: Internet
Author: User
Bat.aspx:
Program code
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Bat.aspx.cs" inherits= "Bat"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>c# Call Batch-jb51.net</title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
<asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "button"/>
<br/>
<asp:label id= "Label1" runat= "Server" text= "Label" width= "304px" ></asp:Label></div>
</form>
</body>

Bat.aspx.cs:
Program Code Program code
Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Diagnostics;
public partial class Bat:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
//
}
protected void Button1_Click (object sender, EventArgs e)
{
System.Diagnostics.Process p = new System.Diagnostics.Process ();
P.startinfo.useshellexecute = false;
P.startinfo.createnowindow = true;//set to False will see the program window
P.startinfo.windowstyle = window state when the process is started processwindowstyle.hidden;//
P.startinfo.redirectstandardoutput = true;
p.StartInfo.FileName = Server.MapPath ("A.bat");
p.StartInfo.FileName = @ "E:\a.bat";//If A.bat is in System32 folder, just fill in the file name here
P.startinfo.workingdirectory = @ "E:\";
p.startinfo.arguments = Server.URLEncode (TextBox1.Text);
P.start ();
Label1.Text = P.standardoutput.readtoend ();
p.WaitForExit ();
P.close ();
}
}

A.bat:
Program code
Copy Code code as follows:

@echo off
MD%random%
Set I=1
: Loop
Ping 1-n 1-w 1000 2>nul 1>nul
set/a i=%i%+1
If%i%==20 echo returns a value:%1^<br^> you, so patient & exit
Goto Loop

Note: When batch processing and ASPX are not in the same directory, it is best to set the initial directory for the process that started with workingdirectory to the directory where the batch is processed, otherwise the batch-created directory in the previous example should be in the directory of ASPX instead of the directory where the batch is located!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.