fx.diagnostics: add linux support for starting processes
This commit is contained in:
@@ -9,11 +9,21 @@ int main(int argc, const char **argv)
|
||||
const char *exec = argv[1];
|
||||
const char *msg = argv[2];
|
||||
|
||||
const char *args[] = {
|
||||
"hello",
|
||||
"world",
|
||||
};
|
||||
|
||||
fx_process *self = fx_process_get_self();
|
||||
const fx_hashtable *env = fx_process_get_environment(self);
|
||||
|
||||
fx_process_start_info info = {
|
||||
.proc_args = NULL,
|
||||
.proc_args_count = 0,
|
||||
.proc_args = args,
|
||||
.proc_args_count = sizeof args / sizeof args[0],
|
||||
.proc_redirect_stdout = true,
|
||||
.proc_redirect_stdin = true,
|
||||
.proc_file_name = exec,
|
||||
.proc_environment = env,
|
||||
};
|
||||
|
||||
fx_process *process = fx_process_create(&info);
|
||||
@@ -30,11 +40,20 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
printf("process stdin: %s\n", msg);
|
||||
|
||||
fx_stream *in = fx_process_get_stdin(process);
|
||||
fx_stream_write_cstr(in, "Hello, world!\n", NULL);
|
||||
fx_stream_write_cstr(in, msg, NULL);
|
||||
fx_stream_write_char(in, '\n');
|
||||
fx_process_close_stdin(process);
|
||||
#endif
|
||||
|
||||
fx_stream *out = fx_process_get_stdout(process);
|
||||
printf("process stdout:\n");
|
||||
printf("---------------------\n");
|
||||
|
||||
while (FX_OK(fx_stream_read_line_s(out, fx_stdout))) { }
|
||||
|
||||
printf("---------------------\n");
|
||||
|
||||
int result;
|
||||
fx_process_wait(process, &result);
|
||||
|
||||
Reference in New Issue
Block a user