which command
emacsが見つからない場合は、$PATH
変数でemacsを見つけるためにemacsパスを見つけるプログラムがあります。私のシステムにemacsを持たせて、以下のプログラムは正しい出力を提供しますが、それは.cshrcファイルを調達しています。理由はわかりませんか?
/* getenv example: getting path */
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sys/stat.h>
using namespace std;
int main ()
{
FILE *fp;
int status;
char path[256];
const char *command = "which emacs 2>&1";
/* Open the command for reading. */
fp = popen(command, "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit(0);
}
string path1;
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
path1 += path;
}
cout<<"orignal path after which command = "<<path1<<endl;
/* close */
bool found = true;
std::string search="which:";
char *tmp;
tmp = strstr(path1.c_str(),search.c_str());
if (tmp != NULL)
{
found = false;
}
else
{
found = true;
}
if (found){
cout<<"Found Emacs"<<endl;
cout<<"path = "<<path1;
string path2;
for (int i=0; i < path1.length()-1; i++)
{
path2 += path1[i];
}
//path1[path1.length()-1]= " ";
path2 += " -i";
cout<<"final path = "<<path2<<endl;}
else
cout<<"Not found Emacs"<<endl;
pclose(fp);
return 0;
}