'Using one instance of shell opened by subprocess in python

I've been trying to execute a few commands using python to automate certain things. I have not found any answers to this question that help me solve this problem.

Basically, I want to execute either a list of commands using one shell opened by subprocess. How can this be achieved?

I have tried the following using os.system(): (I am aware it is becoming depreciated, hence, I'm looking into subprocess)

os.system("powershell; Get-Date >> recent_git_log.txt")
os.system("powershell; git -C "{PATH}" stash 2>>&1 >> recent_git_log.txt")

and so on...

But this is very inefficient, therefore, I need a better way of doing this. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source