'C - Tried to start a text editor using exec system call but vim crashes due to "Error reading input" resembling issue with Nano

Good day!

first time posting on stack overflow. Hope, I get this right.

For an exercise project, I would like my program to start vim or nano (doesn't matter for now) before proceeding.

Using the below code, vim starts. I.e. I can see the vim interface in the terminal window. But: As soon as I start typing, after one or two characters, vim crashes giving me the following output:

Vim: Error reading input, exiting...

Vim: Finished.

Here's my code snippet:

      pid_t childPid = fork();
      if (childPid) {
        // ... 
      }
      else {
       // open [filename.md] in vim
       char * vim = "/bin/vim";
       filePath = "/home/myusername/Documents/test.md";
       execl(vim, vim, filePath, NULL); 
      }

Not sure, if I have to block the input recognition of the parent process or similar.

Guess I went a bit too far for my level of knowledge. It would be great to have a solution anyway. I think knowing a bit of how to solve this, might help when I encounter this topic later on.

c


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source