Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access argc and argv in c++ from a library function

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

like image 661
DanJ Avatar asked Oct 01 '08 23:10

DanJ


2 Answers

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.

like image 112
Darron Avatar answered Oct 23 '22 17:10

Darron


There is the GetCommandLine() function in the Win32 API. On other platforms, you would have to save argc/argv somewhere (external variable?).

like image 20
Martin Cote Avatar answered Oct 23 '22 17:10

Martin Cote