Console isolation

pull/631/head
NextTurn 2020-08-04 00:00:00 +08:00 committed by Next Turn
parent b0423e3156
commit 7e644f7944
2 changed files with 19 additions and 1 deletions

View File

@ -8,6 +8,9 @@ namespace WinSW.Native
{
internal const int ATTACH_PARENT_PROCESS = -1;
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool AllocConsole();
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool AttachConsole(int processId);

View File

@ -255,6 +255,9 @@ namespace WinSW
private void DoStart()
{
bool succeeded = ConsoleApis.FreeConsole();
Debug.Assert(succeeded);
this.HandleFileCopies();
// handle downloads
@ -551,7 +554,19 @@ namespace WinSW
}
}
Process process = Process.Start(startInfo);
bool succeeded = ConsoleApis.AllocConsole();
Debug.Assert(succeeded);
Process process;
try
{
process = Process.Start(startInfo);
}
finally
{
succeeded = ConsoleApis.FreeConsole();
Debug.Assert(succeeded);
}
Log.Info($"Started process {process.Format()}.");