Skip to content

Updades description of the popen module #5117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: latest
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 98 additions & 52 deletions doc/reference/reference_lua/popen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ object:
syscall
* :ref:`popen.new <popen-new>` to create a popen object with more specific options

Either function returns a handle which we will call ``popen_handle`` or ``ph``.
With the handle one can execute methods.
Below are tables with summaries of ``popen`` constructors, constants, mrthods, and fields.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: mrthods.


===============================================================================
Index
===============================================================================

Below is a list of all ``popen`` functions and handle methods.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
popen module constructors
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comment on lines +35 to +37
Copy link
Member

@Totktonada Totktonada May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really place these ToC tables into sub-sections? It is rendered this way:

image

Maybe we can do it in the following way (add the 'summary' words)?

  • Overview
    • popen module constructors summary
    • popen module constants summary
    • popen handle methods summary
    • popen handle fields summary
  • popen module constructors
  • popen module constants
  • popen handle methods
  • popen handle fields

It seems less confusing.


.. container:: table

Expand All @@ -53,6 +50,35 @@ Below is a list of all ``popen`` functions and handle methods.
| :ref:`popen.new() | Execute a child program in |
| <popen-new>` | a new process |
+--------------------------------------+---------------------------------+

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
popen module constants
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. container:: table

.. rst-class:: left-align-column-1
.. rst-class:: left-align-column-2

+--------------------------------------+---------------------------------+
| Name | Use |
+======================================+=================================+
| :ref:`Module constants | Module constants |
| <popen-constants>` | |
+--------------------------------------+---------------------------------+

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
popen module methods
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comment on lines +70 to +72
Copy link
Member

@Totktonada Totktonada May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are handle methods.


.. container:: table

.. rst-class:: left-align-column-1
.. rst-class:: left-align-column-2

+--------------------------------------+---------------------------------+
| Name | Use |
+======================================+=================================+
| :ref:`popen_handle:read() | Read data from a child peer |
| <popen-read>` | |
+--------------------------------------+---------------------------------+
Expand Down Expand Up @@ -80,13 +106,27 @@ Below is a list of all ``popen`` functions and handle methods.
| :ref:`popen_handle:close() | Close a popen handle |
| <popen-close>` | |
+--------------------------------------+---------------------------------+
| :ref:`Module constants | Module constants |
| <popen-constants>` | |

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
popen module fields
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. container:: table

.. rst-class:: left-align-column-1
.. rst-class:: left-align-column-2

+--------------------------------------+---------------------------------+
| Name | Use |
+======================================+=================================+
| :ref:`Handle fields | Handle fields |
| <popen-handle_fields>` | |
+--------------------------------------+---------------------------------+

===============================================================================
popen module constructors
===============================================================================

.. _popen-shell:

.. function:: shell(command [, mode])
Expand All @@ -95,8 +135,7 @@ Below is a list of all ``popen`` functions and handle methods.

:param string command: a command to run, mandatory
:param string mode: communication mode, optional
:return: (if success) a popen handle, which we will call
``popen_handle`` or ``ph``
:return: (if success) a popen handle object

(if failure) ``nil, err``

Expand Down Expand Up @@ -160,8 +199,7 @@ Below is a list of all ``popen`` functions and handle methods.
mandatory; absolute path to the program is required when
``opts.shell`` is false (default)
:param table opts: table of options, optional
:return: (if success) a popen handle, which we will call
``popen_handle`` or ``ph``
:return: (if success) a popen handle object

(if failure) ``nil, err``

Expand Down Expand Up @@ -251,7 +289,7 @@ Below is a list of all ``popen`` functions and handle methods.
| | | or when Lua GC collects the handle. |
+----------------------+----------------+-------------------------------------------+

The returned ``ph`` handle provides a
The returned ``popen_handle`` handle provides a
:ref:`popen_handle:close() <popen-close>` method for explicitly
releasing all occupied resources, including the child process
itself if ``opts.keep_child`` is not set). However, if the ``close()``
Expand Down Expand Up @@ -382,9 +420,39 @@ Below is a list of all ``popen`` functions and handle methods.
return table.concat(chunks):rstrip()
end

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
popen handle methods
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
===============================================================================
popen module constants
===============================================================================

.. _popen-constants:

**Module constants**

.. code-block:: none

- popen.opts
- INHERIT (== 'inherit')
- DEVNULL (== 'devnull')
- CLOSE (== 'close')
- PIPE (== 'pipe')

- popen.signal
- SIGTERM (== 9)
- SIGKILL (== 15)
- ...

- popen.state
- ALIVE (== 'alive')
- EXITED (== 'exited')
- SIGNALED (== 'signaled')

- popen.stream
- OPEN (== 'open')
- CLOSED (== 'closed')

===============================================================================
popen handle methods
===============================================================================

.. class:: popen_handle

Expand All @@ -394,7 +462,7 @@ Below is a list of all ``popen`` functions and handle methods.

Read data from a child peer.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:param table opts: options
Expand Down Expand Up @@ -437,7 +505,7 @@ Below is a list of all ``popen`` functions and handle methods.

Write string ``str`` to stdin stream of a child process.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:param string str: string to write
Expand Down Expand Up @@ -480,7 +548,7 @@ Below is a list of all ``popen`` functions and handle methods.

Close parent's ends of std* fds.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:param table opts: options
Expand Down Expand Up @@ -535,7 +603,7 @@ Below is a list of all ``popen`` functions and handle methods.

Send SIGTERM signal to a child process.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:return: see :ref:`popen_handle:signal() <popen-signal>` for errors and
Expand All @@ -551,7 +619,7 @@ Below is a list of all ``popen`` functions and handle methods.

Send SIGKILL signal to a child process.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:return: see :ref:`popen_handle:signal() <popen-signal>` for errors and
Expand All @@ -568,7 +636,7 @@ Below is a list of all ``popen`` functions and handle methods.

Send signal to a child process.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:param number signo: signal to send
Expand Down Expand Up @@ -611,7 +679,7 @@ Below is a list of all ``popen`` functions and handle methods.

Return information about the popen handle.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:return: (if success) formatted result
Expand Down Expand Up @@ -743,7 +811,7 @@ Below is a list of all ``popen`` functions and handle methods.

Wait until a child process gets exited or signaled.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:param number timeout: since version :doc:`3.2.0 </release/3.2.0>`. The parameter defines the period in seconds for the method to wait for a resolution. The default value is "infinity".
Expand Down Expand Up @@ -785,7 +853,7 @@ Below is a list of all ``popen`` functions and handle methods.

Close a popen handle.

:param handle ph: handle of a child process created with
:param userdata ph: handle of a child process created with
:ref:`popen.new() <popen-new>` or
:ref:`popen.shell() <popen-shell>`
:return: (if success) true
Expand Down Expand Up @@ -835,6 +903,10 @@ Below is a list of all ``popen`` functions and handle methods.
means success for a caller. The return values are purely
informational: they are for logging or some kind of reporting.

===============================================================================
popen handle fields
===============================================================================

.. _popen-handle_fields:

**Handle fields**
Expand All @@ -850,29 +922,3 @@ Below is a list of all ``popen`` functions and handle methods.
popen_handle.stderr

See :ref:`popen_handle:info() <popen-info>` for details.

.. _popen-constants:

**Module constants**

.. code-block:: none

- popen.opts
- INHERIT (== 'inherit')
- DEVNULL (== 'devnull')
- CLOSE (== 'close')
- PIPE (== 'pipe')

- popen.signal
- SIGTERM (== 9)
- SIGKILL (== 15)
- ...

- popen.state
- ALIVE (== 'alive')
- EXITED (== 'exited')
- SIGNALED (== 'signaled')

- popen.stream
- OPEN (== 'open')
- CLOSED (== 'closed')