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.
How to get the exe path using the runtime struct?
150 Views Asked by BBasile At
3
There are 3 best solutions below
3

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.
I can confirm that the runtime returns empty values when a
WinMain
function is used (even after the call toRuntime.initialize
).Maybe Druntime should try and call the WinAPI functions to fill up the
rt_args
/rt_cArgs
members if the compiler finds aWinMain
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.