Reputation: 2081
I am noobie with C.
I've seen system()
and fork()
and execv()
stuff, but I do not think they are what I need ( or they just do not work )
I just want to my C program to open vim immediately of a file path to edit, then i can quit vim and the program continues, in my case it will just exit.
Think like git commit
, it opens vim for me then when I save+exit it sends the commit.
Any ideas?
Upvotes: 0
Views: 302
Reputation: 12708
System(3)
will do the work, but beware that if you call your program with the input/output redirected not to a terminal, this will propagate to the execution of vim
and it will not work.
vim(3)
requires that the input and output are directed to a terminal line, it cannot work on redirected input, so the best way to call it should be (with system()
):
system("/usr/bin/vim file </dev/tty >/dev/tty");
The redirection clauses specify that the input and the output be redirected to the session controlling terminal, so you'll get it working even if you have redirected standard input/output in the main program.
Upvotes: 2
Reputation: 2081
system()
is what I was looking for, I was using it incorrectly, but it's simple just use:
system("vim path/to/file.txt");
will open vim of current directy and work like expected ( like git commit
)
Upvotes: 2