Created
September 27, 2017 08:11
-
-
Save jintao-zero/88f0ce2083c681c418ff9bb49ca3491c to your computer and use it in GitHub Desktop.
linux c/c++ get exe path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <limits.h> | |
#include <unistd.h> | |
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(int argc, char *argv[]) | |
{ | |
std::cout << getexepath() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment