From fd20050fc9749aac75b412c1ecaf97b3977b1b4e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 4 Nov 2013 14:15:19 -0800 Subject: [PATCH] First hack at fixing console IO --- app/atom_main.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/atom_main.cc b/app/atom_main.cc index b2f4c7cda2c5..14463962bee5 100644 --- a/app/atom_main.cc +++ b/app/atom_main.cc @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include "content/public/app/content_main.h" @@ -21,10 +24,48 @@ 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); + } + scoped_ptr env(base::Environment::Create()); std::string node_indicator; if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) &&