Get Running EXE Path && Change Working Path Under Linux

Get Running EXE Path && Change Working Path Under Linux


得到目前正在执行的程序路径,并切换 working directory 至此路径。



char buf[256] = {''};
char *pch;
 
readlink("/proc/self/exe", buf, sizeof(buf));
if (pch = strrchr(buf, '/'))
{
	*pch = '';
	printf("working directory:%sn", buf);
	chdir(buf);
}

Dotblogs 的标签: CPP ,Dir ,Unix