From: Paul Betts Date: Tue, 5 Nov 2013 00:56:50 +0000 (-0800) Subject: This method seems to work, :shipit: X-Git-Tag: v0.6.8~4^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=60f24eb22b1f75d25e52b52a607b5a877ebe1e12;p=electron.git This method seems to work, :shipit: --- diff --git a/app/atom_main.cc b/app/atom_main.cc index 14463962..f0193bf3 100644 --- a/app/atom_main.cc +++ b/app/atom_main.cc @@ -24,47 +24,18 @@ int Start(int argc, char *argv[]); #include "content/public/app/startup_helper_win.h" #include "sandbox/win/src/sandbox_types.h" -/* - * An alternate way to skin the same cat - -void ConnectStdioToConsole() -{ - int hCrt; - AllocConsole(); - - HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); - hCrt = _open_osfhandle((long) handle_out, _O_TEXT); - FILE* hf_out = _fdopen(hCrt, "w"); - setvbuf(hf_out, NULL, _IONBF, 1); - *stdout = *hf_out; - - HANDLE handle_err = GetStdHandle(STD_ERROR_HANDLE); - hCrt = _open_osfhandle((long) handle_err, _O_TEXT); - FILE* hf_err = _fdopen(hCrt, "w"); - setvbuf(hf_err, NULL, _IONBF, 1); - *stderr = *hf_err; - - - HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE); - hCrt = _open_osfhandle((long) handle_in, _O_TEXT); - FILE* hf_in = _fdopen(hCrt, "r"); - setvbuf(hf_in, NULL, _IONBF, 128); - *stdin = *hf_in; -} -*/ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { int argc = 0; wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); // Attach to the parent console if we've got one so that stdio works - if (GetConsoleWindow()) { - AllocConsole() ; - AttachConsole(GetCurrentProcessId()); - freopen("CON", "w", stdout); - freopen("CON", "w", stderr); - freopen("CON", "r", stdin); - } + AttachConsole(ATTACH_PARENT_PROCESS); + + FILE* dontcare; + freopen_s(&dontcare, "CON", "w", stdout); + freopen_s(&dontcare, "CON", "w", stderr); + freopen_s(&dontcare, "CON", "r", stdin); scoped_ptr env(base::Environment::Create()); std::string node_indicator;