diff options
author | wm4 <wm4@nowhere> | 2015-01-01 20:04:38 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-01-01 20:04:38 +0100 |
commit | 44701238c73ba8f50fb16c675e2db3555902ac7a (patch) | |
tree | bb2db125fa0ca7c6774abe3ac99e44fb3c75c4aa /osdep/subprocess-posix.c | |
parent | bafb9b22715313ef0049630228a744d7f2c9363b (diff) | |
download | mpv-44701238c73ba8f50fb16c675e2db3555902ac7a.tar.bz2 mpv-44701238c73ba8f50fb16c675e2db3555902ac7a.tar.xz |
subprocess: allow disabling redirection of stdout/stderr
If the stdout or stderr write callback is NULL, then don't redirect this
stream. Preparation for the next commit.
Not sure what to do on Windows; it seems STARTUPINFO doesn't allow
redirection only one of them. So just let them write nothing. For our
intended use-case (next commit), this is probably sensible.
Diffstat (limited to 'osdep/subprocess-posix.c')
-rw-r--r-- | osdep/subprocess-posix.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/osdep/subprocess-posix.c b/osdep/subprocess-posix.c index 82af7c5f50..e56e2401f7 100644 --- a/osdep/subprocess-posix.c +++ b/osdep/subprocess-posix.c @@ -66,18 +66,18 @@ int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx, int p_stderr[2] = {-1, -1}; pid_t pid = -1; - if (mp_make_cloexec_pipe(p_stdout) < 0) + if (on_stdout && mp_make_cloexec_pipe(p_stdout) < 0) goto done; - if (mp_make_cloexec_pipe(p_stderr) < 0) + if (on_stderr && mp_make_cloexec_pipe(p_stderr) < 0) goto done; if (posix_spawn_file_actions_init(&fa)) goto done; fa_destroy = true; // redirect stdout and stderr - if (posix_spawn_file_actions_adddup2(&fa, p_stdout[1], 1)) + if (p_stdout[1] >= 0 && posix_spawn_file_actions_adddup2(&fa, p_stdout[1], 1)) goto done; - if (posix_spawn_file_actions_adddup2(&fa, p_stderr[1], 2)) + if (p_stderr[1] >= 0 && posix_spawn_file_actions_adddup2(&fa, p_stderr[1], 2)) goto done; if (posix_spawnp(&pid, args[0], &fa, NULL, args, environ)) { |