From ef032cbe85b46584304c665b539b4f7561c4c26c Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 13 Feb 2012 20:55:29 +0100 Subject: [PATCH] Windows: support non-ansi command line arguments --- src/node.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/node.cc b/src/node.cc index 9ac528a85d7..f6ae19da928 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2045,12 +2045,40 @@ Handle SetupProcessObject(int argc, char *argv[]) { process->Set(String::NewSymbol("platform"), String::New(PLATFORM)); // process.argv +#ifdef _WIN32 + // Windows - use unicode + WCHAR* command_line = GetCommandLineW(); + if (command_line == NULL) { + winapi_perror("GetCommandLineW"); + exit(1); + } + + int wargc = 0; + WCHAR** wargv = CommandLineToArgvW(command_line, &wargc); + if (wargv == NULL || wargc <= 0) { + winapi_perror("CommandLineToArgvW"); + exit(1); + } + + assert(wargc == argc); + + Local arguments = Array::New(wargc - option_end_index + 1); + arguments->Set(Integer::New(0), String::New(reinterpret_cast(wargv[0]))); + for (j = 1, i = option_end_index; i < wargc; j++, i++) { + Local arg = String::New(reinterpret_cast(wargv[i])); + arguments->Set(Integer::New(j), arg); + } + + LocalFree(wargv); +#else + // Unix Local arguments = Array::New(argc - option_end_index + 1); arguments->Set(Integer::New(0), String::New(argv[0])); for (j = 1, i = option_end_index; i < argc; j++, i++) { Local arg = String::New(argv[i]); arguments->Set(Integer::New(j), arg); } +#endif // assign it process->Set(String::NewSymbol("argv"), arguments);