I’m working on a Streamlit script to run a script file (.sh) through the command line in a Linux environment. I examined this thread in the documentation for guidance, but no luck so far. The script runs without an error, but the script file itself doesn’t run. I’ve tried to see if the issue is a path error, but the path info looks good.
Here’s the sample code:
import streamlit as st
import subprocess
import sys
st.title("Test Script")
st.header("Test")
button1 = st.button("Click me")
if button1:
subprocess.run([f"{sys.executable}", "/home/user/grader_2/Scripts/0_texts.sh"])
st.write("finished")
The .sh file looks like this:
cd /home/user/grader_2/essays/TXTs
pylanguagetool text_0.txt > Comments_0.txt
Any advice or suggestions for invoking a script in command line through Streamlit? Many thanks for any ideas.
When you call {sys.executable}, this is calling a Python interpreter. But you’re passing a shell script to it. Have you tried bash or sh instead of {sys.executable}?
Good news, the script executes. However, there’s still a problem I can’t account for. The subprocess command executes the script file, writing a new comments_0.txt in the correct directory. However, there’s an error in the execution. The comments_0.txt contains an error of “input file is required”, and the subprocess result returns returncode=2. When I run the pylanguagetool text_0.txt > comments_0.txt directly in the terminal the command executes properly, with the comments_0.txt written with the proper input file of text_0.txt.
This reply from Stack Overflow believed the problem is a problem of recognizing the shell properly. Any thoughts? Thanks again!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.