I'm writing a library which is to be dynamically loaded in C++.
I'd like to read argc and argv (for debugging reasons) from within my code, however I do not have access to the main function. Is there any way to retrieve the command line (both Windows and Linux solution would be nice).
Thanks, Dan
On Linux the pseudo-file /proc/self/cmdline holds the command line for the process. Each argument is terminated with a 0 byte, and the final argument is followed by an additional 0 byte.
There is the GetCommandLine() function in the Win32 API. On other platforms, you would have to save argc/argv somewhere (external variable?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With