Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Windows: support non-ansi command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Feb 13, 2012
1 parent 2e6ad62 commit ef032cb
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/node.cc
Expand Up @@ -2045,12 +2045,40 @@ Handle<Object> 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<Array> arguments = Array::New(wargc - option_end_index + 1);
arguments->Set(Integer::New(0), String::New(reinterpret_cast<uint16_t*>(wargv[0])));
for (j = 1, i = option_end_index; i < wargc; j++, i++) {
Local<String> arg = String::New(reinterpret_cast<uint16_t*>(wargv[i]));
arguments->Set(Integer::New(j), arg);
}

LocalFree(wargv);
#else
// Unix
Local<Array> 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<String> arg = String::New(argv[i]);
arguments->Set(Integer::New(j), arg);
}
#endif
// assign it
process->Set(String::NewSymbol("argv"), arguments);

Expand Down

0 comments on commit ef032cb

Please sign in to comment.