ASP.NET equivalent to Python's os.system([string])
Question: I have an app made in Python, which accesses a Linux server's command prompt
with `os.system([string])`

Now I'd like to transfer this away from Python, into some language like
ASP.NET or something.

Is there a way to access the server's command prompt and run commands with
ASP.NET or any technology found in Visual Studio?

This needs to run in a web app, where a user will click a button, and then a
server-side command will run, so it's important that the technology suggested
is compatible with all that.


Answer: Well it isn't ASP.net specific but in c#:

    
    
    using System.Diagnostics;
    
    Process.Start([string]);
    

Or With more access to the specific parts of running a program (like
arguments, and output streams)

    
    
    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();
    

here is how you could combine this with an ASPx Page:

First 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>
    

Then the code behind:

    
    
    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();
                };
            }
        }
    }
    

