<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses &#187; Console</title>
	<atom:link href="http://huddledmasses.org/tag/console/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>A Better Get-Credential in one line of code</title>
		<link>http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/</link>
		<comments>http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 21:14:54 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[Credentials]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/</guid>
		<description><![CDATA[For too long I have ignored the deficiencies in Get-Credential, so now I am going to fix them. Ready? function Get-Credential&#40;$caption,$msg,$domain,$name&#41;&#123;$Host.UI.PromptForCredential&#40;$caption,$msg,$name,$domain&#41;&#125; Ok, that&#8217;s better than the default, whew! At least you can specify the prompt text and the domain and default user name &#8230; but there are so many other options that are missing from [...]]]></description>
			<content:encoded><![CDATA[	<p>For too long I have ignored the deficiencies in Get-Credential, so now I am going to fix them. Ready?</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Credential</span></span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$caption</span>,<span style="color: #660033; font-weight: bold;">$msg</span>,<span style="color: #660033; font-weight: bold;">$domain</span>,<span style="color: #660033; font-weight: bold;">$name</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$Host</span>.<span style="color: #003366;">UI</span>.<span style="color: #003366;">PromptForCredential</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$caption</span>,<span style="color: #660033; font-weight: bold;">$msg</span>,<span style="color: #660033; font-weight: bold;">$name</span>,<span style="color: #660033; font-weight: bold;">$domain</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#125;</span></div>

	<p>Ok, that&#8217;s better than the default, whew!  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' />  At least you can specify the prompt text and the domain and default user name &#8230; but there are so many other options that are missing from that dialog &#8212;like remembering my credentials for goodness sakes. I know many places forbid using the &#8220;remember&#8221; option for credentials, but why is that decision not up to me?</p>

	<p>Well, I can&#8217;t make all of those options appear (at least, not without compiling a pinvoke function to call the Win32 <span class="caps">API</span>) nor can I force PowerShell to use the <a href="http://msdn.microsoft.com/en-us/library/aa375178(VS.85).aspx">new Vista/2008 Credential function</a> (which is Common Criteria compliant in Vista) instead of the older <a href="http://msdn.microsoft.com/en-us/library/aa375177(VS.85).aspx">CredUIPromptForCredentials</a> ... but I can give you the <a href="https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=370658&#38;SiteID=99">most requested feature</a> for Get-Credential: a -Console option to force the prompt to happen in the console instead of in a &#8220;CredUI&#8221; pop up.  </p>

	<p> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Note:</strong> I kind-of messed up here, this will break if you&#8217;re used to using the -Credential parameter for Get-Credential to provide a default user name.  I&#8217;ll fix it shortly.</p>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/681"></script></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NativeConsole.cs &#8211; Run console apps and get their output</title>
		<link>http://huddledmasses.org/nativeconsolecs-run-console-apps-and-get-their-output/</link>
		<comments>http://huddledmasses.org/nativeconsolecs-run-console-apps-and-get-their-output/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 18:53:18 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=649</guid>
		<description><![CDATA[To those of you who are not software developers: feel free to skip this post A while ago I wrote a little class for calling console apps from a .Net application, and I&#8217;ve been using it in several of my apps (most notably in PoshConsole) and it works great, but since the only place I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[	<p>To those of you who are not software developers: feel free to skip this post  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> </p>

	<p>A while ago I wrote a little class for calling console apps from a .Net application, and I&#8217;ve been using it in several of my apps (most notably in <a href="http://CodePlex.com/PoshConsole">PoshConsole</a>) and it works great, but since the only place I&#8217;ve really published it is in PoshConsole, I thought I&#8217;d write it up here, and share it with you &#8230;</p>

	<p>Basically, it&#8217;s a slick invisible event-based wrapper around the Windows native console.  What I mean is, it calls AllocConsole when it&#8217;s instantiated to create a native console, and hides the console window so it doesn&#8217;t show up. This allows you to run any console app you need to from within your app without having it popup a black window  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' />  Note this doesn&#8217;t let you run graphical consoles like <span class="caps">EDIT</span>.<span class="caps">COM</span>, but it can handle interactive apps like cmd.exe, batch files, or ftp.exe).  All you really have to do is create one of my NativeConsole objects, handle its WriteOutputLine and WriteErrorLine events &#8230; and use its WriteInput method to send input or commands to the console app.</p>

	<p>You can check out how it works in my WPF-based PoshConsole, and you can get the latest version of it from that project as well (it&#8217;s in \trunk\Huddled\Interop\NativeConsole.cs) but for now, here&#8217;s the single file source code, with a more liberal set of licenses than I allow for PoshConsole.<span id="more-649"></span></p>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #008080; font-style: italic;">// Copyright (c) 2008 Joel Bennett</span><br />
<br />
<span style="color: #008080; font-style: italic;">// Permission is hereby granted, free of charge, to any person obtaining a copy </span><br />
<span style="color: #008080; font-style: italic;">// of this software and associated documentation files (the &quot;Software&quot;), to deal</span><br />
<span style="color: #008080; font-style: italic;">// in the Software without restriction, including without limitation the rights </span><br />
<span style="color: #008080; font-style: italic;">// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell </span><br />
<span style="color: #008080; font-style: italic;">// copies of the Software, and to permit persons to whom the Software is </span><br />
<span style="color: #008080; font-style: italic;">// furnished to do so, subject to the following conditions:</span><br />
<br />
<span style="color: #008080; font-style: italic;">// The above copyright notice and this permission notice shall be included in </span><br />
<span style="color: #008080; font-style: italic;">// all copies or substantial portions of the Software.</span><br />
<br />
<span style="color: #008080; font-style: italic;">// THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR </span><br />
<span style="color: #008080; font-style: italic;">// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, </span><br />
<span style="color: #008080; font-style: italic;">// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE </span><br />
<span style="color: #008080; font-style: italic;">// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER </span><br />
<span style="color: #008080; font-style: italic;">// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span><br />
<span style="color: #008080; font-style: italic;">// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE </span><br />
<span style="color: #008080; font-style: italic;">// SOFTWARE.</span><br />
<br />
<span style="color: #008080; font-style: italic;">// *****************************************************************************</span><br />
<span style="color: #008080; font-style: italic;">// NOTE: YOU MAY *ALSO* DISTRIBUTE THIS FILE UNDER ANY OF THE FOLLOWING LICENSES:</span><br />
<span style="color: #008080; font-style: italic;">// BSD: &nbsp; http://opensource.org/licenses/bsd-license.php</span><br />
<span style="color: #008080; font-style: italic;">// MIT: &nbsp; http://opensource.org/licenses/mit-license.html</span><br />
<span style="color: #008080; font-style: italic;">// Ms-PL: http://opensource.org/licenses/ms-pl.html</span><br />
<span style="color: #008080; font-style: italic;">// GPL 2: http://opensource.org/licenses/gpl-2.0.php</span><br />
<br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Diagnostics</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF;">namespace</span> Huddled.<span style="color: #0000FF;">Interop</span><br />
<span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp;<span style="color: #008080; font-style: italic;">/// A wrapper around AllocConsole, with some nice eventing to handle</span><br />
&nbsp; &nbsp;<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> NativeConsole <span style="color: #008000;">:</span> IDisposable<br />
&nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The API/Interop/PInvoke methods for the NativeConsole </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">internal</span> <span style="color: #FF0000;">class</span> NativeMethods<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080;">#region &nbsp;Fields (5)</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> UInt32 DUPLICATE_SAME_ACCESS <span style="color: #008000;">=</span> 0x00000002<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> LWA_ALPHA <span style="color: #008000;">=</span> 0x2<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> LWA_COLORKEY <span style="color: #008000;">=</span> 0x1<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> WS_EX_LAYERED <span style="color: #008000;">=</span> 0x80000<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> WS_EX_TRANSPARENT <span style="color: #008000;">=</span> 0x00000020<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080;">#region &nbsp;Enums (3)</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> ShowState <span style="color: #008000;">:</span> <span style="color: #FF0000;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SW_HIDE <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// and lots of others</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> GwlIndex <span style="color: #008000;">:</span> <span style="color: #FF0000;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Id <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Style <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">16</span><span style="color: #000000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExStyle <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">20</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> StdHandle <span style="color: #008000;">:</span> <span style="color: #FF0000;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The standard input device</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INPUT_HANDLE <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">10</span>, <span style="color: #008080; font-style: italic;">//(DWORD)-10 &nbsp; &nbsp;The standard input device.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The standard output device.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OUTPUT_HANDLE <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">11</span>, <span style="color: #008080; font-style: italic;">//(DWORD)-11 &nbsp; The standard output device.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The standard error device.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ERROR_HANDLE <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">12</span> <span style="color: #008080; font-style: italic;">//(DWORD)-12 &nbsp;The standard error device.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080;">#region &nbsp;Methods (13)</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// &nbsp;Public Methods (13)</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span><span style="color: #0600FF;">return</span><span style="color: #008000;">:</span> MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> AllocConsole<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span><span style="color: #0600FF;">return</span><span style="color: #008000;">:</span> MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> CloseHandle<span style="color: #000000;">&#40;</span>IntPtr hHandle<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span><span style="color: #0600FF;">return</span><span style="color: #008000;">:</span> MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> CreatePipe<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">out</span> IntPtr hReadPipe, <span style="color: #0600FF;">out</span> IntPtr hWritePipe, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">ref</span> SECURITY_ATTRIBUTES lpPipeAttributes, <span style="color: #FF0000;">uint</span> nSize<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> DuplicateHandle<span style="color: #000000;">&#40;</span>IntPtr hSourceProcessHandle,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr hSourceHandle, IntPtr hTargetProcessHandle, <span style="color: #0600FF;">out</span> IntPtr lpTargetHandle,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">uint</span> dwDesiredAccess, <span style="color: #FF0000;">bool</span> bInheritHandle, <span style="color: #FF0000;">uint</span> dwOptions<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>, ExactSpelling <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span><span style="color: #0600FF;">return</span><span style="color: #008000;">:</span> MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> FreeConsole<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> IntPtr GetConsoleWindow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">int</span> GetWindowLong<span style="color: #000000;">&#40;</span>IntPtr hWnd, GwlIndex nIndex<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> ReadFile<span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IntPtr hFile, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// handle to file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> lpBuffer, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// data buffer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">int</span> nNumberOfBytesToRead, &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// number of bytes to read</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">out</span> <span style="color: #FF0000;">int</span> lpNumberOfBytesRead, &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// number of bytes read</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IntPtr overlapped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// overlapped buffer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> SetLayeredWindowAttributes<span style="color: #000000;">&#40;</span>IntPtr hwnd, <span style="color: #FF0000;">int</span> crKey, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">byte</span> bAlpha, <span style="color: #FF0000;">int</span> dwFlags<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span><span style="color: #0600FF;">return</span><span style="color: #008000;">:</span> MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> SetStdHandle<span style="color: #000000;">&#40;</span>StdHandle nStdHandle, IntPtr hHandle<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">int</span> SetWindowLong<span style="color: #000000;">&#40;</span>IntPtr hWnd, GwlIndex nIndex, <span style="color: #FF0000;">int</span> dwNewLong<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span><span style="color: #0600FF;">return</span><span style="color: #008000;">:</span> MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> ShowWindow<span style="color: #000000;">&#40;</span>IntPtr hWnd, ShowState nCmdShow<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;kernel32.dll&quot;</span>, SetLastError <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">int</span> WriteFile<span style="color: #000000;">&#40;</span>IntPtr hFile, <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> buffer,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">int</span> numBytesToWrite, <span style="color: #0600FF;">out</span> <span style="color: #FF0000;">int</span> numBytesWritten, IntPtr lpOverlapped<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#91;</span>StructLayout<span style="color: #000000;">&#40;</span>LayoutKind.<span style="color: #0000FF;">Sequential</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">struct</span> SECURITY_ATTRIBUTES<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> nLength<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> IntPtr lpSecurityDescriptor<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>MarshalAs<span style="color: #000000;">&#40;</span>UnmanagedType.<span style="color: #FF0000;">Bool</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> bInheritHandle<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> OutputEventArgs<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Text<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Delegate and Events (3)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Delegate, I changed this to be compatible with normal wpf/forms events</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">delegate</span> <span style="color: #0600FF;">void</span> OutputDelegate<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> source, OutputEventArgs args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Events (2)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> OutputDelegate WriteErrorLine<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> OutputDelegate WriteOutputLine<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region &nbsp;Private Fields (14)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Track whether Dispose has been called.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> disposed <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// A nice handle to our console window</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> IntPtr handle<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// And our process</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Process</span> process<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Our two threads</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> Thread outputThread, errorThread<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// and the original handles to the console</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> IntPtr stdOutRead, stdOutWrite, stdInRead, stdInWrite, stdErrRead, stdErrWrite<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// and the copy handles ...</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> IntPtr stdOutReadCopy, stdInWriteCopy, stdErrReadCopy<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region &nbsp;Constructors and Destructors (2)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;Initializes a new instance of the &lt;see cref=&quot;NativeConsole&quot;/&gt; class.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> NativeConsole<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Make ourselves a nice console</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">AllocConsole</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// hide the window ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;handle <span style="color: #008000;">=</span> NativeMethods.<span style="color: #0000FF;">GetConsoleWindow</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">ShowWindow</span><span style="color: #000000;">&#40;</span>handle, NativeMethods.<span style="color: #0000FF;">ShowState</span>.<span style="color: #0000FF;">SW_HIDE</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//NativeMethods.SetWindowLong(handle, NativeMethods.GwlIndex.ExStyle, </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// (NativeMethods.GetWindowLong(handle, NativeMethods.GwlIndex.ExStyle) |</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// NativeMethods.WS_EX_LAYERED | NativeMethods.WS_EX_TRANSPARENT));</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//NativeMethods.SetLayeredWindowAttributes(handle, 0, 0, NativeMethods.LWA_ALPHA);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;process <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Process</span>.<span style="color: #0000FF;">GetCurrentProcess</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">SECURITY_ATTRIBUTES</span> saAttr<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Set the bInheritHandle flag so pipe handles are inherited.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;saAttr.<span style="color: #0000FF;">nLength</span> <span style="color: #008000;">=</span> Marshal.<a href="http://www.google.com/search?q=sizeof+msdn.microsoft.com"><span style="color: #008000;">SizeOf</span></a><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>NativeMethods.<span style="color: #0000FF;">SECURITY_ATTRIBUTES</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;saAttr.<span style="color: #0000FF;">bInheritHandle</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;saAttr.<span style="color: #0000FF;">lpSecurityDescriptor</span> <span style="color: #008000;">=</span> IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #008000;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// The steps for redirecting STDOUT:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Create anonymous pipe to be STDOUT for us.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Set STDOUT of our process to be WRITE handle to the pipe.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Create a (noninheritable) duplicate of the read handle, and...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Close the inheritable read handle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">CreatePipe</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">out</span> stdOutRead, <span style="color: #0600FF;">out</span> stdOutWrite, <span style="color: #0600FF;">ref</span> saAttr, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't create the STDOUT pipe&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">SetStdHandle</span><span style="color: #000000;">&#40;</span>NativeMethods.<span style="color: #0000FF;">StdHandle</span>.<span style="color: #0000FF;">OUTPUT_HANDLE</span>, stdOutWrite<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't redirect STDOUT!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Create noninheritable read handle and close the inheritable read handle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">DuplicateHandle</span><span style="color: #000000;">&#40;</span>process.<span style="color: #0000FF;">Handle</span>, stdOutRead, process.<span style="color: #0000FF;">Handle</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">out</span> stdOutReadCopy, <span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">false</span>, NativeMethods.<span style="color: #0000FF;">DUPLICATE_SAME_ACCESS</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't Duplicate STDOUT Handle&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdOutRead<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// For the output handles we need a thread to read them</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outputThread <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thread<span style="color: #000000;">&#40;</span>OutputThread<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outputThread.<span style="color: #0000FF;">SetApartmentState</span><span style="color: #000000;">&#40;</span>ApartmentState.<span style="color: #0000FF;">STA</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outputThread.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// The steps for redirecting STDERR are the same:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Create anonymous pipe to be STDERR for us.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Set STDERR of our process to be WRITE handle to the pipe.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Create a (noninheritable) duplicate of the read handle and </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Close the inheritable read handle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">CreatePipe</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">out</span> stdErrRead, <span style="color: #0600FF;">out</span> stdErrWrite, <span style="color: #0600FF;">ref</span> saAttr, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't create the STDERR pipe&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">SetStdHandle</span><span style="color: #000000;">&#40;</span>NativeMethods.<span style="color: #0000FF;">StdHandle</span>.<span style="color: #0000FF;">ERROR_HANDLE</span>, stdErrWrite<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't redirect STDERR!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Create noninheritable read handle and close the inheritable read handle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">DuplicateHandle</span><span style="color: #000000;">&#40;</span>process.<span style="color: #0000FF;">Handle</span>, stdErrRead, process.<span style="color: #0000FF;">Handle</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">out</span> stdErrReadCopy, <span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">false</span>, NativeMethods.<span style="color: #0000FF;">DUPLICATE_SAME_ACCESS</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't Duplicate STDERR Handle&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdErrRead<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// For the output handles we need a thread to read them</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorThread <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thread<span style="color: #000000;">&#40;</span>ErrorThread<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorThread.<span style="color: #0000FF;">SetApartmentState</span><span style="color: #000000;">&#40;</span>ApartmentState.<span style="color: #0000FF;">STA</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorThread.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// The steps for redirecting STDIN:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Create anonymous pipe to be STDIN for us.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Set STDIN of our process to be READ handle to the pipe.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Create a (noninheritable) duplicate of the WRITE handle and </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// * Close the inheritable WRITE handle.</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">CreatePipe</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">out</span> stdInRead, <span style="color: #0600FF;">out</span> stdInWrite, <span style="color: #0600FF;">ref</span> saAttr, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't create the StdIn pipe&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">SetStdHandle</span><span style="color: #000000;">&#40;</span>NativeMethods.<span style="color: #0000FF;">StdHandle</span>.<span style="color: #0000FF;">INPUT_HANDLE</span>, stdInRead<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't redirect StdIn!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Create noninheritable read handle and close the inheritable read handle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>NativeMethods.<span style="color: #0000FF;">DuplicateHandle</span><span style="color: #000000;">&#40;</span>process.<span style="color: #0000FF;">Handle</span>, stdInWrite, process.<span style="color: #0000FF;">Handle</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">out</span> stdInWriteCopy, <span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">false</span>, NativeMethods.<span style="color: #0000FF;">DUPLICATE_SAME_ACCESS</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Trace</span>.<span style="color: #0000FF;">TraceError</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Couldn't Duplicate StdIn Handle&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdInWrite<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;Releases unmanaged resources and performs other cleanup operations </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// before the &lt;see cref=&quot;Console&quot;/&gt; is reclaimed by garbage collection.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Use C# destructor syntax for finalization code.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// This destructor will run only if the Dispose method does not get called.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;NOTE: Do not provide destructors in types derived from this class.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/remarks&gt;</span><br />
&nbsp; &nbsp; &nbsp; ~NativeConsole<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Instead of cleaning up in BOTH Dispose() and here ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// We call Dispose(false) for the best readability and maintainability.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dispose<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Methods (5)</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// &nbsp;Public Methods (2)</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Implement IDisposable</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Performs application-defined tasks associated with </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// freeing, releasing, or resetting unmanaged resources.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// This object will be cleaned up by the Dispose method.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Therefore, we call GC.SupressFinalize to tell the runtime </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// that we dont' need to be finalized (we would clean up twice)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GC.<span style="color: #0000FF;">SuppressFinalize</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dispose<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Writes the input.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;input&quot;&gt;The input.&lt;/param&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> WriteInput<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> input<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> bytes <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">UTF8Encoding</span>.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span>input<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">int</span> written<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">int</span> hresult <span style="color: #008000;">=</span> NativeMethods.<span style="color: #0000FF;">WriteFile</span><span style="color: #000000;">&#40;</span>stdInWriteCopy, bytes, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bytes.<span style="color: #0000FF;">Length</span>, <span style="color: #0600FF;">out</span> written, IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>hresult <span style="color: #008000;">!=</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Error Writing to StdIn, HRESULT: &quot;</span> <span style="color: #008000;">+</span> hresult.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// &nbsp;Private Methods (3)</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Handles actual cleanup actions, under two different scenarios</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;disposing&quot;&gt;if set to &lt;c&gt;true&lt;/c&gt; we've been called directly or </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// indirectly by user code and can clean up both managed and unmanaged resources.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Otherwise it's been called from the destructor/finalizer and we can't</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// reference other managed objects (they might already be disposed).</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;/param&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> Dispose<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span> disposing<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Check to see if Dispose has already been called.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>disposed<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// // If disposing equals true, dispose all managed resources ALSO.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>disposing<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorThread.<span style="color: #0000FF;">Abort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputThread.<span style="color: #0000FF;">Abort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//WriteInput(&quot;\n&quot;);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> bytes <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">UTF8Encoding</span>.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">char</span><span style="color: #000000;">&#41;</span><span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">int</span> written<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeMethods.<span style="color: #0000FF;">WriteFile</span><span style="color: #000000;">&#40;</span>stdErrWrite, bytes, bytes.<span style="color: #0000FF;">Length</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">out</span> written, IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeMethods.<span style="color: #0000FF;">WriteFile</span><span style="color: #000000;">&#40;</span>stdOutWrite, bytes, bytes.<span style="color: #0000FF;">Length</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">out</span> written, IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//errorThread.Join();</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//outputThread.Join();</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Clean up UnManaged resources</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// If disposing is false, only the following code is executed.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">FreeConsole</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//NativeMethods.CloseHandle(stdOutWrite);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//NativeMethods.CloseHandle(stdOutReadCopy);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//NativeMethods.CloseHandle(stdErrWrite);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//NativeMethods.CloseHandle(stdErrReadCopy);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdInWriteCopy<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdInRead<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception e<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Trace.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Trace.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">StackTrace</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;disposed <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The ErrorThread ThreadStart delegate</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> ErrorThread<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">int</span> BytesRead<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> BufBytes <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4096</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// consider wrapping this in a System.IO.FileStream</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>NativeMethods.<span style="color: #0000FF;">ReadFile</span><span style="color: #000000;">&#40;</span>stdErrReadCopy, BufBytes, <span style="color: #FF0000;">4096</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">out</span> BytesRead, IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>WriteErrorLine <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteErrorLine<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OutputEventArgs <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Text <span style="color: #008000;">=</span> UTF8Encoding.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>BufBytes, <span style="color: #FF0000;">0</span>, BytesRead<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>ThreadAbortException<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">finally</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdErrWrite<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdErrReadCopy<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The OutputThread ThreadStart delegate</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> OutputThread<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">int</span> BytesRead<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> BufBytes <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4096</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// consider wrapping this in a System.IO.FileStream</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>NativeMethods.<span style="color: #0000FF;">ReadFile</span><span style="color: #000000;">&#40;</span>stdOutReadCopy, BufBytes, <span style="color: #FF0000;">4096</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">out</span> BytesRead, IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>WriteOutputLine <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteOutputLine<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OutputEventArgs <span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Text <span style="color: #008000;">=</span> UTF8Encoding.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>BufBytes, <span style="color: #FF0000;">0</span>, BytesRead<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>ThreadAbortException<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">finally</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdOutWrite<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeMethods.<span style="color: #0000FF;">CloseHandle</span><span style="color: #000000;">&#40;</span>stdOutReadCopy<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/nativeconsolecs-run-console-apps-and-get-their-output/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

