国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# 批處理調(diào)用方法

2020-01-24 03:47:10
字體:
供稿:網(wǎng)友
Bat.aspx:
程序代碼 
復制代碼 代碼如下:

<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#調(diào)用批處理-VeVB.COm</title>
</head>
<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>
</html>

Bat.aspx.cs:
程序代碼 程序代碼
復制代碼 代碼如下:

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;//設置為false將會看到程序窗口
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//啟動進程時窗口狀態(tài)
p.StartInfo.RedirectStandardOutput = true;
//p.StartInfo.FileName = Server.MapPath("a.bat");
p.StartInfo.FileName = @"E:/a.bat";//如果a.bat在System32文件夾中,此處只需填寫文件名即可
p.StartInfo.WorkingDirectory = @"E:/";
p.StartInfo.Arguments = Server.UrlEncode(TextBox1.Text);
p.Start();
Label1.Text = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
}

a.bat:
程序代碼
復制代碼 代碼如下:

@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 返回值:%1^<br^>服了你,這么有耐心 & exit
goto loop

說明:當批處理和aspx不在同一目錄中時,最好用WorkingDirectory設置啟動的進程的初始目錄為批處理所在目錄,否則如上例中批處理新建的目錄就應在aspx所在目錄中而不是批處理所在目錄了!
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 广丰县| 南安市| 格尔木市| 衡东县| 柘荣县| 黄浦区| 泽州县| 武穴市| 于田县| 长汀县| 白银市| 张家口市| 荆门市| 华容县| 济源市| 桂林市| 社旗县| 大冶市| 互助| 夹江县| 三明市| 昆山市| 上林县| 黔南| 澄迈县| 罗平县| 囊谦县| 深水埗区| 金沙县| 南宫市| 金山区| 东宁县| 珲春市| 富阳市| 临江市| 沅江市| 红河县| 华亭县| 应城市| 内黄县| 错那县|