ASP.NET相当于Python的使用os.system([字符串])

问题描述:

我在Python开发的应用,其访问与os.system([string])ASP.NET相当于Python的使用os.system([字符串])

Linux服务器的命令提示现在,我想在Python远转移此,转换成ASP.NET之类的语言

有没有办法访问服务器的命令提示符,并使用ASP.NET或Visual Studio中的任何技术运行命令?

这需要运行在一个web应用程序中,用户将点击一个按钮,然后运行一个服务器端命令,因此建议的技术与所有这些都是兼容的。

+1

http://*.com/questions/247668/running-command-line-from-an-aspx-page-and-returning-output-to-page – Damith

+0

我添加了一个完整的ASPx示例,调用一个Process并将其输出设置为一个ASP元素。 –

那么它是不是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(); 
      }; 
     } 
    } 
} 
+0

这整件事对我来说是未知的水域,但是有没有一种方法可以在Web应用程序中运行此C#代码?如在,用户点击一些东西,然后这个代码被触发。 – Houseman

+0

在Web应用程序中,如果您想要访问页面以触发此代码,或者在“_OnClick()”事件中使用Page_Load()函数时,此代码将附加到后面的代码中,如果要在点击“

+0

好的,我会告诉你的话。谢谢。顺便说一句,有什么新手教程,这将帮助我熟悉asp.net和c#脚本?我也会研究,但我想我会问。 – Houseman