Open a terminal window and run script using st.button

Hi everyone,

Using streamlit first time and already my head is full of potential apps I want to make with it beyond the data science stuff. So, here goes my question.

One of the thing I am doing is trying to run another python script from the terminal on the Mac after clicking a button. Basically, the user will be using the dropdowns to select a few options which will be used as arguments to my other python script. To open the terminal, I use the following.

run_button = st.button(β€˜Run’)
command = f"osascript -e β€˜tell application {final_app} to do script {final_command}’"

if run_button:
os.popen(command).read()

However, no new terminal opens. No error comes up as well. Any hints on how to accomplish this?

Thanks!

Hi @excalibre, welcome to the Streamlit community!

While running a subprocess isn’t uncommon, actually bringing up a terminal window is a bit less so. I’m not sure that a browser-based app (i.e. a web page) has the ability to do that (I’m not certain).

For hints on how to use a subprocess in a Streamlit app, please see the docs where we give a minimal example:

Best,
Randy

If I understood, you don’t want to show a terminal window. You want to execute a command when the button is clicked. In this case, you can use a lib called Paramiko, and execute the command via ssh

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.