History

command: extend subprocess command stdin, change behavior

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.

wm4 committed 6 years ago

Commit e27c5231 parent d6bf3887 files · +110 −6Browse files

Showing the changes to TOOLS/lua/command-test.lua (1 of 7 files). Show all

Unified · Split

TOOLS/lua/command-test.lua+19−0
@@ -76,6 +76,25 @@ mp.observe_property("vo-configured", "bool", function(_, v) · 75 unmodified lines
76 end)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 -- This should get killed on script exit.99 -- This should get killed on script exit.
81 mp.command_native_async({name = "subprocess", playback_only = false,100 mp.command_native_async({name = "subprocess", playback_only = false,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t