Skip to content

Commit

Permalink
add example for run_shell
Browse files Browse the repository at this point in the history
  • Loading branch information
wang0618 committed Nov 3, 2023
1 parent b4509c0 commit 6de5c4d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pywebio_battery/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def run_shell(cmd: str, output_func=partial(put_text, inline=True), encoding='ut
.. versionchanged:: 0.4
add ``encoding`` parameter and return code
.. exportable-codeblock::
:name: battery-run-shell
:summary: Run shell and output to code block
cmd = "ls -l"
put_logbox('shell_output')
run_shell(cmd, output_func=lambda msg: logbox_append('shell_output', msg))
"""
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
try:
Expand Down

0 comments on commit 6de5c4d

Please sign in to comment.