When I use os.system()
or subprocess.run()
with commands I want to run in the brackets, it runs it like typing the command in a command prompt or terminal.
But for example I were to do cd <my directory>
to change my directory, and then afterwards I do a cd
to display the current directory of the terminal, it would just always go back to the default directory.
Like I started on C:\Users\MYNAME, and I were to do a cd Desktop
to go change directory to desktop, I expect it to change directory to C:\Users\MYNAME\Desktop, which it does in that instance, but when I use the command again, it would bring me back to C:\Users\MYNAME
I want it to be able to keep the shell being sort of "active", so when I use my python program to run cmd scripts, it would continue from the last instance, instead of like starting a new one.
(SORRY THIS IS MY FIRST TIME USING STACKOVERFLOW, I DON'T REALLY KNOW HOW TO TYPE THINGS HERE :D:D:D)
Here is my code:
import os, subprocess
while True:
try:
try:
subprocess.run(usr_input, shell= True) # Or os.system(usr_input)
except Exception as e:
print(f'error:{e}')
usr_input = input('INPUT:')
except Exception as e:
print(e)