Make it possible to feed a string to stdin of a subprocess. Out of laziness, it can't be an arbitrary byte string. (Would require adding an option type that takes in a Lua byte string.) Do not set stdin of a subprocess to fd 0 (i.e. mpv's stdin) anymore, because it makes things more consistent. Enabling stdin didn't make too much sense in the first place, so this behavior change seems justifiable. win32 support missing.
Showing the changes to TOOLS/lua/command-test.lua (1 of 7 files). Show all
Unified · Split
| @@ -76,6 +76,25 @@ mp.observe_property("vo-configured", "bool", function(_, v) · 75 unmodified lines | ||
| 76 | 76 | end) |
| 77 | 77 | |
| 78 | 78 | |
| 79 | + mp.command_native_async({name = "subprocess", args = {"wc", "-c"}, | |
| 80 | + stdin_data = "hello", capture_stdout = true}, | |
| 81 | + function(res, val, err) | |
| 82 | + print("Should be '5': " .. val.stdout) | |
| 83 | + end) | |
| 84 | + -- blocking stdin by default | |
| 85 | + mp.command_native_async({name = "subprocess", args = {"cat"}, | |
| 86 | + capture_stdout = true}, | |
| 87 | + function(res, val, err) | |
| 88 | + print("Should be 0: " .. #val.stdout) | |
| 89 | + end) | |
| 90 | + -- stdin + detached | |
| 91 | + mp.command_native_async({name = "subprocess", | |
| 92 | + args = {"bash", "-c", "(sleep 5s ; cat)"}, | |
| 93 | + stdin_data = "this should appear after 5s.\n", | |
| 94 | + detach = true}, | |
| 95 | + function(res, val, err) | |
| 96 | + print("5s test: " .. val.status) | |
| 97 | + end) | |
| 79 | 98 | |
| 80 | 99 | -- This should get killed on script exit. |
| 81 | 100 | mp.command_native_async({name = "subprocess", playback_only = false, |