a4e797f619
the fx.diagnostics namespace includes a process class for starting and managing processes
45 lines
868 B
C
45 lines
868 B
C
#include <fx/diagnostics/process.h>
|
|
|
|
int main(int argc, const char **argv)
|
|
{
|
|
if (argc < 3) {
|
|
return -1;
|
|
}
|
|
|
|
const char *exec = argv[1];
|
|
const char *msg = argv[2];
|
|
|
|
fx_process_start_info info = {
|
|
.proc_args = NULL,
|
|
.proc_args_count = 0,
|
|
.proc_redirect_stdin = true,
|
|
.proc_file_name = exec,
|
|
};
|
|
|
|
fx_process *process = fx_process_create(&info);
|
|
if (!process) {
|
|
fprintf(stderr, "Process creation failed\n");
|
|
return -1;
|
|
}
|
|
|
|
fx_status status = fx_process_start(process);
|
|
if (!FX_OK(status)) {
|
|
fprintf(stderr,
|
|
"Process creation failed: %s\n",
|
|
fx_status_description(status));
|
|
return -1;
|
|
}
|
|
|
|
#if 1
|
|
fx_stream *in = fx_process_get_stdin(process);
|
|
fx_stream_write_cstr(in, "Hello, world!\n", NULL);
|
|
fx_process_close_stdin(process);
|
|
#endif
|
|
|
|
int result;
|
|
fx_process_wait(process, &result);
|
|
fx_process_unref(process);
|
|
|
|
return 0;
|
|
}
|