My problem I am having is when I use execl, it close my main program. I want the program I create can open other programs or create other actions with linux. I am looking to help getting on the right path. Should I be using execl? Why does it close the main program after it runs execl?

while (y0 != "no")
{
        cout << endl;
    cout << "How many I help you? Enter Command";
        cout << endl << "open" << endl << "close" << endl << "delete" << endl << "search" << endl << "Enter what program or file like to action ";
        cin >> y0 >> y1;


if (y0 == "open")
           {
cout << y1 << endl;
         if (y1 == "vlc")
         {
          strcpy(y3, "/usr/bin/");
          strcat (y3, y1);

          cout << "Enter path ";
          cin >> path;
          strcpy (y2, "/home/john/Videos/");
          strcat (y2, path);

          execl (y3,"vlc",y2);
          }


if (y1 != "vlc")
          {
           strcpy(y3, "/usr/bin/");
           strcat (y3, y1);
           execl (y3, "a");
           }

execl is designed to exit your process and start a new one. I've never used it though. Try reading this, it looks like it has some useful information in it.

That link you gave me was for C, is it ok to mix c and c++? I know I am doing it now, does it really matter? Do I have any other choices another then execl to only Lunch a native Linux program that is already installed within my code? I am looking for books or websites to aid me if you have you would suggest.

It's fine to use these functions from in your C++ programs. I'm not familiar with any other ways of doing this. I expect there are some though...

I need another tipper with the same code, change it up little to help resloved my problems. I need to use SQl now to help me pull the needed information. What I need help with is what is best for string to char.

using namespace std;
string programerfinder (string y1);
string pathfinder (string path);
int main()
{
string y1;
string path;
char y2[25];//path enter in search
char y3[330];//stores path for usr bin
y1 = programerfinder (y1);
path = pathfinder (path);


strcat (y3, y1);


execl ("/usr/bin/vlc","vlc");
}

string programerfinder (string y1)
{        
ifstream program;
program.open("program.txt");
getline (program,y1);
program.close();
return (y1);
}
string pathfinder (string path)
{
ifstream pathlist;
pathlist.open("test2.txt");
getline (pathlist,path);
pathlist.close();
return (path);
}

I think you're hijacking your own thread here!

You should probably mark this one as solved and start a new thread with your new question :)

Here, maybe this function can help you: it mimics the function system from Windows:

int system (const char *command){
    int status;
    pid_t pid = fork ();
    if (pid == 0){
        execl ("/bin/sh", "/bin/sh", "-c", command, NULL);
        _exit (EXIT_FAILURE);
    }
    else if (pid < 0) status = -1;
    else 
        if (waitpid (pid, &status, 0) != pid) 
            status = -1;
    return status;
}

See how execl is used to start another process. Also, you could try combining threads with this function, starting a new thread for each call to this function.

commented: so the code above, path and y1 will my what I fill in for vlc +0

it mimics the function system from Windows

system() is a standard C/C++ function, it's available on Linux too. ;) You probably knew that, of course, but your choice of phrase could be confusing to less experienced folks.

system() is a standard C/C++ function, it's available on Linux too. ;) You probably knew that, of course, but your choice of phrase could be confusing to less experienced folks.

Yes, indeed, my bad.
It was a quick example, for the execl function. :)

I added little more to the mixing pot but I thought I was using excel incorrectly at frist. The frist post made it sound like I should not do it that way. So I came up with this way. Please if you know a better way please help. I want to lanch a Linux program that I will not know but will be in usr/bin. I thought to laod the program with this command, then using shell script, keep the program alive that way. I create many small programs that open programs, find paths needed for the programs to open like movies, songs, and text docs etc. Make sure I am clear, I want to open up my resume, so my program will open a word program, find my resume on my computer for me, open the resume. As the user does not need to know where the resume is on the computer or network.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.