From 4476911d45652d99df1e1a66b5aea48d4ef9a070 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 19 Jul 2020 15:36:41 +0200 Subject: manpage: add named arguments "subprocess" example At the same time, this is an example for a command with named arguments. --- DOCS/man/input.rst | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'DOCS') diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 16daa1fb82..6df7890383 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -210,11 +210,10 @@ This applies to certain APIs, such as ``mp.command_native()`` (with tables that have string keys) in Lua scripting, or ``mpv_command_node()`` (with MPV_FORMAT_NODE_MAP) in the C libmpv client API. -Like with array commands, quoting and escaping is inherently not needed in the -normal case. - -The name of each command is defined in each command description in the -`List of Input Commands`_. ``--input-cmdlist`` also lists them. +The name of the command is provided with a ``name`` string field. The name of +each command is defined in each command description in the +`List of Input Commands`_. ``--input-cmdlist`` also lists them. See the +``subprocess`` command for an example. Some commands do not support named arguments (e.g. ``run`` command). You need to use APIs that pass arguments as arrays. @@ -597,6 +596,23 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_). run while the player is in idle mode, or if you don't want that end of playback kills the command. + .. admonition:: Example + + :: + + local r = mp.command_native({ + name = "subprocess", + playback_only = false, + capture_stdout = true, + args = {"cat", "/proc/cpuinfo"}, + }) + if r.status == 0 then + print("result: " .. r.stdout) + end + + This is a fairly useless Lua example, which demonstrates how to run + a process in a blocking manner, and retrieving its stdout output. + ``quit []`` Exit the player. If an argument is given, it's used as process exit code. -- cgit v1.2.3