From 0279a44d93a378fbdff393d6568a691817f83518 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 17 Jul 2020 01:34:46 +0200 Subject: command: extend subprocess command Add env and detach arguments. This means the command.c code must use the "new" mp_subprocess2(). So also take this as an opportunity to clean up. win32 support gets broken by it, because it never made the switch to the newer function. The new detach parameter makes the "run" command fully redundant, but I guess we'll keep it for simplicity. But change its implementation to use mp_subprocess2() (couldn't do this earlier, because win32). Privately, I'm going to use the "env" argument to add a key binding that starts a shell with a FILE environment variable set to the currently playing file, so this is very useful to me. Note: breaks windows, so for example youtube-dl on windows will not work anymore. mp_subprocess2() has to be implemented. The old functions are gone, and subprocess-win.c is not built anymore. It will probably work on Cygwin. --- test/tests.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/tests.c b/test/tests.c index d8df43f319..eb55bb302b 100644 --- a/test/tests.c +++ b/test/tests.c @@ -118,13 +118,19 @@ void assert_text_files_equal_impl(const char *file, int line, char *path_ref = mp_tprintf(4096, "%s/%s", ctx->ref_path, ref); char *path_new = mp_tprintf(4096, "%s/%s", ctx->out_path, new); - char *errstr = NULL; - int res = mp_subprocess((char*[]){"diff", "-u", "--", path_ref, path_new, 0}, - NULL, NULL, NULL, NULL, &errstr); + struct mp_subprocess_opts opts = { + .exe = "diff", + .args = (char*[]){"diff", "-u", "--", path_ref, path_new, 0}, + .fds = { {0, .src_fd = 0}, {1, .src_fd = 1}, {2, .src_fd = 2} }, + .num_fds = 3, + }; + + struct mp_subprocess_result res; + mp_subprocess2(&opts, &res); - if (res) { - if (res == 1) - MP_WARN(ctx, "Note: %s\n", err); + if (res.error || res.exit_status) { + if (res.error) + MP_WARN(ctx, "Note: %s\n", mp_subprocess_err_str(res.error)); MP_FATAL(ctx, "Giving up.\n"); abort(); } -- cgit v1.2.3