Merge pull request #122 from atom/fix-console-stdio

Fix console STDIO
This commit is contained in:
Cheng Zhao 2013-11-04 17:11:53 -08:00
commit 8112fe741e

View file

@ -4,6 +4,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
@ -21,10 +24,19 @@ int Start(int argc, char *argv[]);
#include "content/public/app/startup_helper_win.h" #include "content/public/app/startup_helper_win.h"
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
int argc = 0; int argc = 0;
wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
// Attach to the parent console if we've got one so that stdio works
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<base::Environment> env(base::Environment::Create()); scoped_ptr<base::Environment> env(base::Environment::Create());
std::string node_indicator; std::string node_indicator;
if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) && if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) &&