ASP.NET相当于Python的使用os.system([字符串])
问题描述:
我在Python开发的应用,其访问与os.system([string])
ASP.NET相当于Python的使用os.system([字符串])
Linux服务器的命令提示现在,我想在Python远转移此,转换成ASP.NET之类的语言
有没有办法访问服务器的命令提示符,并使用ASP.NET或Visual Studio中的任何技术运行命令?
这需要运行在一个web应用程序中,用户将点击一个按钮,然后运行一个服务器端命令,因此建议的技术与所有这些都是兼容的。
答
那么它是不是ASP.net具体,但在C#:
using System.Diagnostics;
Process.Start([string]);
或多个接入运行的程序的特定部分(比如参数和输出流)
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c dir *.cs";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
这里是你如何能有一个ASPX页面组合这样的:
首先Process.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Process.aspx.cs" Inherits="com.gnld.web.promote.Process" %>
<!DOCTYPE html>
<html>
<head>
<title>Test Process</title>
<style>
textarea { width: 100%; height: 600px }
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="RunCommand" runat="server" Text="Run Dir" onclick="RunCommand_Click" />
<h1>Output</h1>
<asp:TextBox ID="CommandOutput" runat="server" ReadOnly="true" TextMode="MultiLine" />
</form>
</body>
</html>
然后后面的代码:
using System;
namespace com.gnld.web.promote
{
public partial class Process : System.Web.UI.Page
{
protected void RunCommand_Click(object sender, EventArgs e)
{
using (var cmd = new System.Diagnostics.Process()
{
StartInfo = new System.Diagnostics.ProcessStartInfo()
{
FileName = "cmd.exe",
Arguments = "/c dir *.*",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
}
})
{
cmd.Start();
CommandOutput.Text = cmd.StandardOutput.ReadToEnd();
};
}
}
}
http://*.com/questions/247668/running-command-line-from-an-aspx-page-and-returning-output-to-page – Damith
我添加了一个完整的ASPx示例,调用一个Process并将其输出设置为一个ASP元素。 –