获得一个程序在执行时的路径
2012-02-20 13:25
309 查看
string fullFileName = "";
// Code taken from: http://www.gamedev.net/community/forums/topic.asp?topic_id=459511
std::string path = "";
pid_t pid = getpid();
char buf[20] = {0};
sprintf(buf,"%d",pid);
std::string _link = "/proc/";
_link.append( buf );
_link.append( "/exe");
char proc[512];
int ch = readlink(_link.c_str(),proc,512);
if (ch != -1) {
proc[ch] = 0;
path = proc;
std::string::size_type t = path.find_last_of("/");
path = path.substr(0,t);
}
fullFileName = path + string("/");
// Code taken from: http://www.gamedev.net/community/forums/topic.asp?topic_id=459511
std::string path = "";
pid_t pid = getpid();
char buf[20] = {0};
sprintf(buf,"%d",pid);
std::string _link = "/proc/";
_link.append( buf );
_link.append( "/exe");
char proc[512];
int ch = readlink(_link.c_str(),proc,512);
if (ch != -1) {
proc[ch] = 0;
path = proc;
std::string::size_type t = path.find_last_of("/");
path = path.substr(0,t);
}
fullFileName = path + string("/");
相关文章推荐
- 在程序中获得可执行文件的路径
- 在Linux程序中如何获得本进程的可执行文件的全路径?
- 如何获得当前执行程序所在的路径
- 在Linux程序中如何获得本进程的可执行文件的全路径?
- Visual C++ Tips: 程序执行路径,一个容易被忽视的问题
- QT中如何获得执行程序的路径
- 获得当前执行程序所在文件夹路径
- volatile变量在多线程同步时运用的优点: 1、锁一次只允许一个线程访问值,volatile 允许多个线程执行读操作,因此当使用 volatile 保证读代码路径时,要比使用锁执行全部代码路径获得
- 拖文件夹或者文件到可执行程序上,获得文件完整路径的方式
- 01线程是一个程序里不同的执行路径
- 01线程是一个程序里不同的执行路径
- SaveDialog执行后程序当前路径跟其变动
- Cron 的在ubuntu 定时执行自己的程序&& Python获取当前 脚本文件的路径。
- 执行完一个外部程序之后再执行另一个程序
- python获取程序执行文件路径方法
- ios写程序的总结(获得归档路径,获得当前时间)
- 从Linux程序中执行shell(程序、脚本)并获得输出结果
- 判断ShellExecute函数是否执行完一个程序的方法
- 如何制作一个可执行的java程序
- 一个用Spring AOP实现异常处理和记录程序执行时间的实例--邵京国