-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.cpp
More file actions
35 lines (33 loc) · 904 Bytes
/
editor.cpp
File metadata and controls
35 lines (33 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <iostream>
using namespace std;
int main (int argc, char* argv[]) {
if(argc != 2) {
cout << "Usage:" << endl;
cout << "./editor <filename>" << endl;
return EXIT_FAILURE;
}
pid_t processId = fork();
if (processId == 0) {
char cmd[] = "vim";
char* const cmd_argv[] = { cmd, argv[1], NULL };
execvp(cmd, cmd_argv);
cout << "Unknown command" << endl;
return EXIT_FAILURE;
} else if (processId < 0) {
cout << "Fork failed." << endl;
return EXIT_FAILURE;
} else {
pid_t tpid;
int child_status;
tpid = wait(&child_status);
if(tpid == -1) {
cout << "Vim didn't exit properly." << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}