1 #include <stdio.h>
2 #include <inttypes.h>
3
4 #include <uv.h>
5
6 uv_loop_t *loop;
7 uv_process_t child_req;
8 uv_process_options_t options;
9
on_exit(uv_process_t * req,int64_t exit_status,int term_signal)10 void on_exit(uv_process_t *req, int64_t exit_status, int term_signal) {
11 fprintf(stderr, "Process exited with status %" PRId64 ", signal %d\n", exit_status, term_signal);
12 uv_close((uv_handle_t*) req, NULL);
13 }
14
main()15 int main() {
16 loop = uv_default_loop();
17
18 char* args[3];
19 args[0] = "mkdir";
20 args[1] = "test-dir";
21 args[2] = NULL;
22
23 options.exit_cb = on_exit;
24 options.file = "mkdir";
25 options.args = args;
26
27 int r;
28 if ((r = uv_spawn(loop, &child_req, &options))) {
29 fprintf(stderr, "%s\n", uv_strerror(r));
30 return 1;
31 } else {
32 fprintf(stderr, "Launched process with ID %d\n", child_req.pid);
33 }
34
35 return uv_run(loop, UV_RUN_DEFAULT);
36 }
37