Created
September 25, 2017 10:29
-
-
Save hisasann/11565cf2be47e71f18fa8882328d3a27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace AttachConsoleSample | |
{ | |
class Program | |
{ | |
[DllImport("kernel32.dll")] | |
public static extern bool AttachConsole(uint dwProcessId); | |
[DllImport("kernel32.dll")] | |
public static extern bool FreeConsole(); | |
private bool writeConsole( string msg ) { | |
if ( !AttachConsole( System.UInt32.MaxValue ) ) { | |
return false; | |
} | |
// stdoutのストリームを取得 | |
System.IO.Stream stream = System.Console.OpenStandardOutput(); | |
System.IO.StreamWriter stdout = new System.IO.StreamWriter( stream ); | |
// 指定された文字列を出力 | |
stdout.Write( msg ); | |
stdout.Flush(); | |
FreeConsole(); | |
return true; | |
} | |
static void Main(string[] args) | |
{ | |
writeConsole("出力!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment