Domanda

Under win7 the runtime (module) never gives me anything. I'd expect the first argument to always be the exe path but it's always empty.

È stato utile?

Soluzione

I can confirm that the runtime returns empty values when a WinMain function is used (even after the call to Runtime.initialize).

Maybe Druntime should try and call the WinAPI functions to fill up the rt_args/rt_cArgs members if the compiler finds a WinMain function. Typically one would use GetCommandLine or CommandLineToArgvW to extract the arguments. A bug should probably be filed for this to bugzilla.

As for the actual path of the current process, there is an open pull request that should make it into the next 2.064 release.

Altri suggerimenti

If it is just to get the current path, std.file.getcwd() gives you the current directory.

C:\work\so> dmd bbasile01.d

C:\work\so> bbasile01.exe
C:\work\so\bbasile01.exe

C:\work\so> type bbasile01.d
import std.stdio;

int main(string[] args) {
  writeln(args[0]);
  return 0;
} // main() function

Writing a cross-platform implementation of a function that gives running process path is not a trivial task... It has been discussed here on the StackOverflow in the past in hundreds of (not D related) threads.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top