How to catch output of shell program or any other processhttp://forums.asp.net/t/882296.aspx/1?How+to+catch+output+of+shell+program+or+any+other+processTue, 03 May 2005 11:32:18 -0400882296914224http://forums.asp.net/p/882296/914224.aspx/1?How+to+catch+output+of+shell+program+or+any+other+processHow to catch output of shell program or any other process Example from my blog. Shows how to catch output of any process. I tested this code using netstat.exe as process to run.<br> <br> <pre><font color="#ffff00"><font color="#000000" style="background-color:rgb(255,255,0)">&lt;%@ Import Namespace=&quot;System.Diagnostics&quot; %&gt;</font></font><br><font color="#0000ff">&lt;</font><font color="#990000">script</font> <font color="#ff0000">runat</font><font color="#0000ff">=&quot;server&quot;</font> <font color="#ff0000">language</font><font color="#0000ff">=&quot;C#&quot;&gt;<br>private void</font> Page_Load()<br>{<br> <font color="#0000ff">string</font> sPath = &quot;path to my program&quot;;<br> <br> ProcessStartInfo proc = <font color="#0000ff">new</font> ProcessStartInfo(sPath, &quot;&quot;);<br> proc.RedirectStandardOutput = <font color="#0000ff">true</font>;<br> proc.UseShellExecute = <font color="#0000ff">false</font>;<br> <br> Process p = Process.Start(proc); <br> p.Start();<br> <font color="#0000ff">this</font>.lblOut.Text = p.StandardOutput.ReadToEnd();<br> p.Dispose();<br>}<br><font color="#0000ff">&lt;/</font><font color="#990000">script</font><font color="#0000ff">&gt;</font><br><font color="#0000ff">&lt;</font><font color="#990000">html</font><font color="#0000ff">&gt;</font><br><font color="#0000ff">&lt;</font><font color="#990000">head</font><font color="#0000ff">&gt;</font><br> <font color="#0000ff">&lt;</font><font color="#990000">title</font><font color="#0000ff">&gt;</font>Shell program output<font color="#0000ff">&lt;/</font><font color="#990000">title</font><font color="#0000ff">&gt;</font><br><font color="#0000ff">&lt;/</font><font color="#990000">head</font><font color="#0000ff">&gt;</font><br><font color="#0000ff">&lt;</font><font color="#990000">body</font><font color="#0000ff">&gt;</font><br> <font color="#0000ff">&lt;</font><font color="#990000">form</font> <font color="#ff0000">runat</font><font color="#0000ff">=&quot;server&quot;&gt;</font><br> <font color="#0000ff">&lt;</font><font color="#990000">pre</font><font color="#0000ff">&gt;&lt;</font><font color="#990000">asp:Label</font> <font color="#ff0000">runat</font><font color="#0000ff">=&quot;server&quot;</font> <font color="#ff0000">id</font><font color="#0000ff">=&quot;lblOut&quot;&gt;&lt;/</font><font color="#990000">asp:Label</font><font color="#0000ff">&gt;&lt;/</font><font color="#990000">pre</font><font color="#0000ff">&gt;</font><br> <font color="#0000ff">&lt;/</font><font color="#990000">form</font><font color="#0000ff">&gt;</font><br><font color="#0000ff">&lt;/</font><font color="#990000">body</font><font color="#0000ff">&gt;</font><br><font color="#0000ff">&lt;/</font><font color="#990000">html</font><font color="#0000ff">&gt;</font></pre> <br> 2005-05-03T11:32:18-04:00