Created
August 2, 2016 16:48
-
-
Save t-mat/cf0c3dc4dec91d033b44eba1f9a4bb0b to your computer and use it in GitHub Desktop.
[UnityEditorExtension] [Windows] AllocConsole for batch-mode
This file contains 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
#if UNITY_EDITOR | |
// unity.exe -projectPath <PATH/TO/YOUR/PROJECT> -batchmode -executeMethod EditorTest.TestFunc -quit | |
using UnityEditor; | |
using System; | |
using System.IO; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
public class EditorTest | |
{ | |
public static void TestFunc() { | |
AttachConsole(); | |
Console.WriteLine("EditorTest.TestFunc : " + DateTime.Now.ToString()); | |
} | |
static void AttachConsole() { | |
#if UNITY_EDITOR_WIN | |
AttachConsole(-1); | |
var stdout = Console.OpenStandardOutput(); | |
var sw = new System.IO.StreamWriter(stdout, Encoding.Default); | |
sw.AutoFlush = true; | |
Console.SetOut(sw); | |
Console.SetError(sw); | |
#endif | |
} | |
#if UNITY_EDITOR_WIN | |
[DllImport("kernel32.dll", SetLastError = true)] | |
static extern bool AttachConsole(int pid); | |
#endif | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment