terminal4 / app.py
skanaujiya's picture
Update app.py
720e97a verified
raw
history blame
1.16 kB
import streamlit as st
import subprocess
# Set the page layout to wide mode for better spacing
st.set_page_config(page_title="Terminal Command Executor", layout="centered")
# Main title
st.title("🖥️ Simple Terminal Emulator")
# Instruction text
st.write("Enter a command and see the result below. This works just like your terminal!")
# Input field for terminal command
command = st.text_input("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'")
# Button to run the command
if st.button("Run Command"):
if command:
try:
# Execute the terminal command and capture the output
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Show the output
if result.stdout:
st.subheader("Output:")
st.code(result.stdout)
# Show any errors if they occur
if result.stderr:
st.subheader("Error:")
st.code(result.stderr)
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.warning("Please enter a command to run.")