Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created September 25, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/2dcf55566ff78891ad03ed6322157c54 to your computer and use it in GitHub Desktop.
Save hisasann/2dcf55566ff78891ad03ed6322157c54 to your computer and use it in GitHub Desktop.
[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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment