diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-01-31 10:25:51 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-02-01 02:28:54 +0100 |
commit | 648fed975eb8ddde9c5cbc0f859d06deebf80dd9 (patch) | |
tree | 604ff116ccf397bcb2cfbbdff62c360f38bce9c1 | |
parent | ec7cbabf0156346b9e5adb8770b4ab71c4efda8e (diff) | |
download | rneovim-648fed975eb8ddde9c5cbc0f859d06deebf80dd9.tar.gz rneovim-648fed975eb8ddde9c5cbc0f859d06deebf80dd9.tar.bz2 rneovim-648fed975eb8ddde9c5cbc0f859d06deebf80dd9.zip |
os_system(): do not set up input stream for empty string #7951
Test failure:
test/functional/eval/system_spec.lua: "works with an empty string"
E5677: Error writing input to shell-command: EPIPE
ref https://github.com/neovim/neovim/pull/6558#issuecomment-361061035
ref #6554
-rw-r--r-- | src/nvim/os/shell.c | 9 | ||||
-rw-r--r-- | test/functional/eval/system_spec.lua | 1 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index e32c6e05d2..c205e4b3af 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -189,6 +189,7 @@ static int do_os_system(char **argv, { out_data_decide_throttle(0); // Initialize throttle decider. out_data_ring(NULL, 0); // Initialize output ring-buffer. + bool has_input = (input != NULL && input[0] != '\0'); // the output buffer DynamicBuffer buf = DYNAMIC_BUFFER_INIT; @@ -212,7 +213,7 @@ static int do_os_system(char **argv, MultiQueue *events = multiqueue_new_child(main_loop.events); proc->events = events; proc->argv = argv; - int status = process_spawn(proc, input != NULL, true, true); + int status = process_spawn(proc, has_input, true, true); if (status) { loop_poll_events(&main_loop, 0); // Failed, probably 'shell' is not executable. @@ -231,7 +232,7 @@ static int do_os_system(char **argv, // deal with stream events as fast a possible. It prevents closing the // streams while there's still data in the OS buffer (due to the process // exiting before all data is read). - if (input != NULL) { + if (has_input) { wstream_init(&proc->in, 0); } rstream_init(&proc->out, 0); @@ -240,8 +241,8 @@ static int do_os_system(char **argv, rstream_start(&proc->err, data_cb, &buf); // write the input, if any - if (input) { - WBuffer *input_buffer = wstream_new_buffer((char *) input, len, 1, NULL); + if (has_input) { + WBuffer *input_buffer = wstream_new_buffer((char *)input, len, 1, NULL); if (!wstream_write(&proc->in, input_buffer)) { // couldn't write, stop the process and tell the user about it diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 77e7424452..7fe79d4351 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -260,6 +260,7 @@ describe('system()', function() end) it('works with an empty string', function() eq("test\n", eval('system("echo test", "")')) + eq(2, eval("1+1")) -- Still alive? end) end) |