0

I'm doing a program where I need user to enter the name of a text file. I want him to be able to see the path if he enters pwd.
Right now this is very OS related and only works on Mac OS(I guess). So I have done

string real;
getline(cin,real);
    if (real == "pwd")
    {
        execl("/bin/pwd","pwd",(char*)NULL);
        wait(1);
    }

My problem is that I want this function to output the full path and then return input to the user so he can decide what to type in next but the shell command runs and then the program stops. Is there any way to basically "sneak" the shell command in there , make it run and then return to the program?

Edited by Dani: Formatting fixed

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by enkitosh
0

I believe that popen will do what you want. Here is some documentation with an example at the bottom of the page.

0

Fantastic! this is exactly what I was looking for. Thank you L7Sqr :D

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.