a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

C# 批處理調用方法

2020-01-24 03:47:10
字體:
來源:轉載
供稿:網友
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#調用批處理-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;//啟動進程時窗口狀態
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所在目錄中而不是批處理所在目錄了!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 91精品久久久久久 | 成人国产精品久久 | 久久91精品 | 久久青青 | 日本精品中文字幕 | 日本在线观看 | 天天舔天天干天天操 | 欧美成在线观看 | 亚洲精品四区 | 日本免费中文字幕 | 国产一区二区影院 | 国产精品中文字幕一区二区三区 | 亚洲精品久久久久avwww潮水 | 日韩精品一区二区三区在线观看 | 精品久久久久久 | 欧美黄色一区二区 | 亚洲第一成年免费网站 | 日本黄色大片免费 | 四虎国产精品成人免费影视 | 亚洲小视频 | 综合一区在线观看 | 亚洲综合色视频在线观看 | 日韩成人在线一区 | 欧美福利视频 | 国产第一亚洲 | 日韩成人久久 | 亚洲视频在线观看网站 | 精品一区二区三区在线观看 | 成人在线播放网站 | 欧美日日干 | 伦理午夜电影免费观看 | www.色在线| 日韩久久综合 | 久久888| 黄网站免费在线观看 | 中文字幕av网 | 亚洲三级视频 | 亚洲国产精久久久久久久 | 亚洲成人精品视频 | 久久网站热最新地址 | www.啪啪 |