2

After executing the first exe, it would do few validation and later I will execute the next exe.

os.system ("C:/Python27/python.exe")

--Few VALIDATION--


os.system ("C:\notepad.exe")

But while execution, I am struck with first exe, after executing os.system ("C:/Python27/python.exe), python doesn't execute the next line.

Kandan Siva
  • 471
  • 2
  • 9
  • 20

1 Answers1

2

Well, os.system execute your python and waits for return (closing, finishing programme). You should use subprocess module. Could you try following code.

subprocess.Popen(['C:/Python27/python.exe'], close_fds=True)
# Few Validation
subprocess.Popen(['C:\notepad.exe'], close_fds=True) # C:\ or C:/

with close_fds (file descriptors), program should run in detached state, so finish script shouldn't finish other spawned process.

Alex Baranowski
  • 1,014
  • 13
  • 22
  • If I use subprocess.Popen(['C:/Python27/python.exe'], close_fds=True), program runs in detached state. But we if I use subprocess.Popen(['C:/Python27/python.exe'], shell=False), I am getting the same result. So what's the difference close_fds=True and shell=False – Kandan Siva Dec 12 '17 at 10:22
  • You use shell true, when you want to have minimal shell enviroment (ex. you have basic path, so you can execute ls command instead of '/usr/bin/ls'). FDS are files descriptors (input (0) output(1) error (2)). Giving close_fds=True says to python that you won't read them, so program can be run in detached state. – Alex Baranowski Dec 12 '17 at 10:36
  • 1
    Well I learned most of them on website called stackoverlow.com :) && python documentation. There is plenty of similar questions like https://stackoverflow.com/questions/1196074/how-to-start-a-background-process-in-python . Have nice day :). – Alex Baranowski Dec 12 '17 at 15:13