1

I am trying to start new command lines from script, for example:

p = subprocess.Popen('start cmd /c "C:\\Program Files\\Redis\\redis-server.exe"', shell=True)

And then get it's children with:

p2 = psutil.Process(pid)
children = p2.children()

However before I am able to do that the process with shell that gets invoked to create my cmd with server started is terminated automatically (the p2 process). Therefore I can't access it's children.

Is there any other way I can access the spawned children or can I stop the shell process from terminating itself?

If I try to start new cmd with shell=False I get "WindowsError: [Error 2] The system cannot find the file specified"

  • 1
    There is no start.exe. That's an internal command of the CMD shell. You can directly execute "C:\Program Files\Redis\redis-server.exe" instead, with the default `shell=False`. If you need a new console, then ask for one via `creationflags=CREATE_NEW_CONSOLE`. – Eryk Sun Sep 25 '17 at 13:14
  • Thank you @eryksun , this simple solution works. – J. Podlaski Sep 26 '17 at 06:01

0 Answers0