How to get path to current exe file on Linux?
- by user1519221
The code below gives current path to exe file on Linux:
#include <iostream>
std::string getExePath()
{
char result[ PATH_MAX ];
ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
return std::string( result, (count > 0) ? count : 0 );
}
int main()
{
std::cout << getExePath() << std::endl;
return 0;
}
…