Score:1

Opening a new terminal from python script and running commands

in flag

I've included my code below. I would like to be able to launch a bash script as part of this python script below which launches a new terminal at a specific directory. The command I'd like to run is 'ls' once the new terminal is launched.

import subprocess
cmd = "gnome-terminal --working-directory=/home/USERNAME/Documents/Scripts/"
subprocess.Popen(cmd, shell=True)

Any ideas on how I might do that?

This is my goal:

  • Upon running script.py from one terminal, I would like it to open a second terminal at a specific directory.
  • Then, either execute a command1 + command2, or just run my bash.sh which has all of my commands already laid out.
  • Leave the terminal open

Any help would be appreciated! Thank you.

Raffa avatar
jp flag
Related: https://askubuntu.com/a/1434392
ardoknow avatar
in flag
Not sure it quite addresses the use of subprocess however. Seems like they're using OS.ssytem. Any other ideas?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.