Add ELECTRON_NO_ATTACH_CONSOLE env var
authorCheng Zhao <zcbenz@gmail.com>
Thu, 26 Nov 2015 13:02:55 +0000 (21:02 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 26 Nov 2015 13:11:28 +0000 (21:11 +0800)
Close #1556.

atom/app/atom_main.cc
docs/api/environment-variables.md

index 88bb137bae0ff257646e7a4b8443fd5cfa2f00fb..5b5df448dfa8849da94b8dd8d6b043a03c6fa352 100644 (file)
@@ -5,7 +5,6 @@
 #include "atom/app/atom_main.h"
 
 #include <stdlib.h>
-#include <string.h>
 
 #if defined(OS_WIN)
 #include <stdio.h>
@@ -57,6 +56,12 @@ bool IsRunAsNode() {
 }
 
 #if defined(OS_WIN)
+bool IsCygwin() {
+  std::string os;
+  scoped_ptr<base::Environment> env(base::Environment::Create());
+  return env->GetVar("OS", &os) && os == "cygwin";
+}
+
 // Win8.1 supports monitor-specific DPI scaling.
 bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
   typedef HRESULT(WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS);
@@ -103,17 +108,13 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
   int argc = 0;
   wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
 
-  scoped_ptr<base::Environment> env(base::Environment::Create());
-
   // Make output work in console if we are not in cygiwn.
-  std::string os;
-  if (env->GetVar("OS", &os) && os != "cygwin") {
+  if (!IsCygwin() && !IsEnvSet("ELECTRON_NO_ATTACH_CONSOLE")) {
     AttachConsole(ATTACH_PARENT_PROCESS);
 
     FILE* dontcare;
     freopen_s(&dontcare, "CON", "w", stdout);
     freopen_s(&dontcare, "CON", "w", stderr);
-    freopen_s(&dontcare, "CON", "r", stdin);
   }
 
   // Convert argv to to UTF8
index b5d3ff3f6f7b799d5d64f6449ce987be2e152fa3..6b000aaa1080f66f28ec42598b99d1c6346d9818 100644 (file)
@@ -37,6 +37,10 @@ Shows Windows's crash dialog when Electron crashed.
 
 This environment variable will not work if `crashReporter` is started.
 
+## `ELECTRON_NO_ATTACH_CONSOLE` _Windows_
+
+Don't attach to current console session.
+
 ## `ELECTRON_FORCE_WINDOW_MENU_BAR` _Linux_
 
 Don't use global menu bar on Linux.