linux 程序内部 查看可执行程序路径
2010-01-05 11:02
246 查看
linux shell pwd 显示当前路径
假若有test.cpp
g++ test.cpp -o test
./test
想在test中找到当前执行程序所在的路径
可以再test.cpp中使用readlink函数
具体见如下实例:
#include<iostream>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
char buff[1024];
memset(buff,0,sizeof(buff));
int n = readlink("/proc/self/exe",buff,1023);
if(n<0)
{
cout<<"Get Path failed"<<endl;
return -1;
}
string path = buff;
int nLen = path.rfind('/');
path.erase(nLen,path.length() - nLen);
cout<<"zui zhong lu jing :"<<path<<endl;
return 0;
}
谨记是/proc/self/exe 在此某人载过跟头
假若有test.cpp
g++ test.cpp -o test
./test
想在test中找到当前执行程序所在的路径
可以再test.cpp中使用readlink函数
具体见如下实例:
#include<iostream>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
char buff[1024];
memset(buff,0,sizeof(buff));
int n = readlink("/proc/self/exe",buff,1023);
if(n<0)
{
cout<<"Get Path failed"<<endl;
return -1;
}
string path = buff;
int nLen = path.rfind('/');
path.erase(nLen,path.length() - nLen);
cout<<"zui zhong lu jing :"<<path<<endl;
return 0;
}
谨记是/proc/self/exe 在此某人载过跟头
相关文章推荐
- Linux查看可执行程序所在路径
- Linux查看可执行程序所在路径
- 怎么在程序内部确定程序自己的绝对路径(windows,linux)
- windos或linux中 which命令 查看当前要执行的命令所在的路径
- Linux/shell命令的实际应用——ldd查看可执行程序依赖的库文件
- 如何查看linux的命令执行路径
- Linux下查看进程的执行文件绝对路径
- Linux如何查看JDK版本号、执行路径、安装路径
- 在Linux下获取当前运行程序可执行文件全路径(不使用real_path()函数)
- linux 下查看某进程的完整执行路径
- linux查看和关闭后台执行程序
- linux下gcc编译可执行程序时,添加动态链接库加载路径
- linux通过端口号查找程序执行路径
- linux查看和关闭后台执行程序
- linux shell 查看进程的可执行程序路径
- Linux环境下查看程序安装路径
- Linux查看程序安装路径
- linux查看和关闭后台执行程序
- 查看linux程序执行的系统日志
- Linux 查看程序安装路径