Is args[0] guaranteed to be the path of execution?

前端 未结 4 2164
别跟我提以往
别跟我提以往 2020-12-11 02:36

This is a fundamental question, but an important one none the less...

When starting a C++ program whose main method has the following common signature:

4条回答
  •  星月不相逢
    2020-12-11 03:25

    No. On Windows GetModuleFileName gurantees the exact full path to the current executing program. On linux there is a symlink /proc/self/exe. Do a readlink on this symlink to get the full path of the currently executing program. Even if youprogram was called thorugh a symlink /proc/self/exe will always point to the actuall program.

提交回复
热议问题