0

When i try to run something like

os.system('start')

or

os.system('start file.txt')

or

os.startfile('file.txt')

it does start console, notepad or whatever, but when my python program executes, those opened programs close as well. So my question is: Is there a way to do things like above, but without closing those programs along with my script?

TheWall
  • 11
  • 1
  • 1
    It seems like you think "executes" means "stops running". For programmers, it normally actually means "starts running" or "continues to run". – Karl Knechtel Aug 06 '21 at 18:11
  • This is simply untrue. You can run Python from your command line, type `import os`, `os.system("start notepad")`, then Ctrl-Z to exit the interpreter, and the Notepad command will continue happily running.. – Tim Roberts Aug 06 '21 at 18:12
  • Sorry, my bad, the reason why it didn`t work for me was that my script was run in vs code. – TheWall Aug 06 '21 at 21:41

1 Answers1

1

It will work with frunction from the subprocess module. Here is an example with Popen :

from subprocess import Popen
p = Popen(['notepad.exe'])

You can also use call

import subprocess
subprocess.call(['calc.exe'])
user_na
  • 2,154
  • 1
  • 16
  • 36