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