Skip to content

Instantly share code, notes, and snippets.

@andfanilo
Created December 12, 2020 16:33
Show Gist options
  • Save andfanilo/aa3e4a6a15124c58e88262e193e1febf to your computer and use it in GitHub Desktop.
Save andfanilo/aa3e4a6a15124c58e88262e193e1febf to your computer and use it in GitHub Desktop.
Output subprocess in Streamlit
import subprocess
import streamlit as st
def run_command(args):
"""Run command, transfer stdout/stderr back into Streamlit and manage error"""
st.info(f"Running '{' '.join(args)}'")
result = subprocess.run(args, capture_output=True, text=True)
try:
result.check_returncode()
st.info(result.stdout)
except subprocess.CalledProcessError as e:
st.error(result.stderr)
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment