system calls - Using fork() and execl() to edit a file in C++ -


i'm writing basic shell application class , need open text editor , edit file in current directory.

this current code doesn't seem working correctly.

cin >> in; pid_t state;     if(in == "e") {         cout << "edit what?: ";         string cmd;         cin >> cmd;         state = fork();         cout << "state: " << state << endl;         if(state == 0) {             execl("pico", cmd.c_str(), (char*) 0);             exit(1);         }         wait(&state);     } 

edit: when above code executed text editor doesn't open , program seems continue through next iteration of main loop.

edit2: when change first execl parameter execl("/usr/bin/pico" ... text editor opens file try edit empty.

running iterm 2 zsh on mac

edit3: got working using execlp instead of execl , adding "-o [dir]" flag arguments.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -