popen not working correctly on sunos5
<p>I have program to find emacs path using <code>which command</code>
if it does not find emacs then i find emacs in <code>$PATH</code> variable.
Lets my system have emacs
then below program is giving output correct <strong>but it is sourcing .cshrc file</strong> I dont know why?</p>

<pre><code>/* getenv example: getting path */
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include &lt;sys/stat.h&gt;
using namespace std;
int main ()
{
    FILE *fp;
    int status;
    char path[256];
    const char *command = "which emacs 2&gt;&amp;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&lt;&lt;"orignal path after which command = "&lt;&lt;path1&lt;&lt;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&lt;&lt;"Found Emacs"&lt;&lt;endl;
        cout&lt;&lt;"path = "&lt;&lt;path1;
        string path2;
        for (int i=0; i &lt; path1.length()-1; i++)
        {
            path2 += path1[i];
        }
        //path1[path1.length()-1]= " ";
        path2 += " -i";
        cout&lt;&lt;"final path = "&lt;&lt;path2&lt;&lt;endl;}
    else
        cout&lt;&lt;"Not found Emacs"&lt;&lt;endl;
    pclose(fp);

    return 0;
}
</code></pre>
