Running a shell command (in a Widget?)

How does one run an external command from within Textual so that the user can enter e.g. the sudo password?

Running a subprocess.check_call in the background works, but not when it’s querying for input.

Ideally, there would be a tmux-like widget where you can embed a terminal, but I guess this is not available yet :slightly_smiling_face:

I would already be happy when the current Textual app would close for a moment, run the external command instead, then reopen again.

Is there a good way to do this except for exiting the Textual app, running the command, then reopening the app from scratch?

If you take a look at this issue

the last comment by me has an example of a widget that can run an interactive program. This is suitable for terminal applications like say, an editor, “top”, etc.

It would work for you to run sudo etc, although, for your purposes, you probably want something more like the python “pexpect” library, which will let you run a program and interact with it. You tell it what prompts you’re expecting from the program and then when it sees them, you can send the password etc.

1 Like