With C/C++, we can get argv[0]:
printf("%s\n",argv[0])
In C#, args begins with argv[1].
Non of bellow API gives exactly argv[0], at least under Linux:
AppDomain.CurrentDomain.FriendlyName: only gives the name, no path
Process.GetCurrentProcess().ProcessName: gives wrong result with symbol link, and no path
Process.GetCurrentProcess().MainModule.FileName: gives wrong result with symbol link, and the path is always absolute
FYI: under Linux with the above C/C++ code (whose result is treated as the golden standard here), it prints the exact path (absolute or relative) that is used to invoke the program, and if you invoke the program through any symbol link, the symbol link's name is printed instead of the real program.
I ask this question since I try to write a wrapper program using C# under Ubuntu, which should pass argv[0] through to be fully transparent in case the wrapped program's behavior depends on argv[0].
printf("%s\n",argv[0])
? – Jeffreyjeffreysvar dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug", string.Empty));
– JeffreyjeffreysAssembly.GetExecutingAssembly().Location
will give you the full path to the assembly. In.Net Core
this will be the DLL, for a.Net Framework
console application this will be the.exe
– Linalinacre