From 527911d2a2047796acd59bae03b075e4425cf73b Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Mon, 30 Mar 2015 01:19:29 +1100 Subject: win32: only attach to the console from mpv.com Previously, mpv.exe used the --terminal option to decide whether to attach to the parent process's console, which made it impossible to tell whether mpv would attach to the console before the config files were parsed. Instead, make mpv always attach to the console when launched from the console wrapper (mpv.com) and never attach otherwise. This will be useful for the next commit, which will use the presence of the console to decide whether to use the pseudo-gui profile. This change should also be an improvement in behavior. The old code would attach to the parent process's console, regardless of whether it was mpv.com or some other program like cmd.exe. This could be confusing, since mpv.exe is marked as a Windows GUI program and shouldn't write text to its parent process's console when launched directly. (See #768.) Visual Studio does something similar with its devenv.com wrapper. devenv.exe only attaches to the console when launched from devenv.com. --- osdep/win32-console-wrapper.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'osdep/win32-console-wrapper.c') diff --git a/osdep/win32-console-wrapper.c b/osdep/win32-console-wrapper.c index c8c297b482..8cebcf8c83 100644 --- a/osdep/win32-console-wrapper.c +++ b/osdep/win32-console-wrapper.c @@ -72,5 +72,9 @@ int wmain(int argc, wchar_t **argv, wchar_t **envp) GetModuleFileNameW(NULL, exe, MAX_PATH); wcscpy(wcsrchr(exe, '.') + 1, L"exe"); + // Set an environment variable so the child process can tell whether it + // was started from this wrapper and attach to the console accordingly + SetEnvironmentVariableW(L"_started_from_console", L"yes"); + return cr_runproc(exe, cmd); } -- cgit v1.2.3