On Friday, 20 May 2016 at 17:41:22 UTC, Adam D. Ruppe wrote:
[...]

Use GetCommandLine to fetch the original thing the user typed, then process it yourself.

[...]

Then why doesn't the following code produce the expected output?

import std.stdio, std.file, std.path;
version (Windows) {
  import core.sys.windows.windows, std.conv;
  pragma(lib, "shell32.lib");
}

enum EXIT_SUCCESS = 0;
enum EXIT_FAILURE = 1;

int main(string[] originalargs) {
  string[] args;
  version (Windows) {
    SetConsoleOutputCP(65001);
    int wargc;
    auto wargs = CommandLineToArgvW(GetCommandLineW(), &wargc);
    if (wargs) {
for(uint i; i < wargc; i++) args ~= buildNormalizedPath(text(wargs[i]));
    } else {
      writeln("Error getting command line arguments.");
      return EXIT_FAILURE;
    }
  } else args = originalargs;
foreach(uint i, string a; args) writefln("Argument %d: '%s'", i, a);
  return EXIT_SUCCESS;
}

Test from Windows:
mytestapp dir1 dir2 "..\my parent dir\"
(all valid arguments)

Output:
Argument 0: 'mytestapp'
Argument 1: 'dir1'
Argument 2: 'dir2'
Argument 3: '..\my parent dir"'

Notice: I had to use std.conv from master branch because otherwise text() wouldn't dereference wargs (of type wchar**).

PS. Please forgive me the delay.

Reply via email to