0

I am trying to create a process that runs two separate bash scripts in separate terminal windows from a Python script that uses subprocess to call them. Currently I have something like this:

if <condition>:
    subprocess.Popen(["bash", "<file1>"]).wait()
    subprocess.Popen(["bash", "<file2>"]).wait()

I keep the wait calls at the end so that they don't overlap and I thought that since Popen() technically runs the calls separately they would run in different terminals. Is there any way to do this so that the two calls never interact or overlap in the same console?

Edit: The reason I need a new console for the second bash script is because the command called at the end of cannot be interrupted by new commands so whenever I have run this process manually I have always just opened a new terminal window to keep them separate. I realize there may be a better way of doing that but I am unaware of what it might be.

9
  • 1
    Does this answer your question? subprocess.Popen in different console Commented Jul 13, 2023 at 19:34
  • Why the terminals and not just background? Are you expecting to interact with them? Commented Jul 13, 2023 at 19:44
  • That answer by @newby73 is outdated and I can't import that same creation flag from subprocess. And in response to Diego I am trying to have them in the background but the problem is one ofthe commands I need to run from my bash script cannot be interrupted by another command in the same terminal Commented Jul 17, 2023 at 15:24
  • 1
    (Remember, most processes running on a typical Linux system aren't attached to a terminal at all; they might be reading and writing to/from FIFOs, pipes, sockets, or any number of other thing that aren't terminals. Moreover, most processes aren't even attached to a GUI subsystem, so there wouldn't be a place to create a window even if one wanted to). Commented Jul 17, 2023 at 15:43
  • 1
    So if you want to start a terminal, you need to do that yourself. See xterm, gnome-terminal, rxvt, and all the other terminals that exist; they can be invoked with subprocess.Popen just as anything else can be. Commented Jul 17, 2023 at 15:44

1 Answer 1

-1

As shown by user1882644 in subprocess.Popen in different console :

To open in a different console, do (tested on Win7 / Python 3):

from subprocess import Popen, CREATE_NEW_CONSOLE

Popen('cmd', creationflags=CREATE_NEW_CONSOLE)

input('Enter to exit from Python script...')

Related How can I spawn new shells to run Python scripts from a base Python script?

Sign up to request clarification or add additional context in comments.

4 Comments

This was the same post as above but that CREATE_NEW_CONSOLE flag must either be deprecated or has changed because I cannot import it and subprocess does not recognize it
The OP is not on Windows, they're on Linux. This flag has never been available on Linux, and it's not supposed to be.
This was tested on Windows 7 with Python 3. These very well may be prerequisites.
Windows is explicitly a prerequisite, as the relevant section of the subprocess documentation indicates, making this answer unsuited to the question it's attached to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.