Python: Howto launch a full process not a child process and retrieve the PID

前端 未结 3 1876
感情败类
感情败类 2020-12-15 08:22

I would like:

  1. Launch a new process (myexe.exe arg1) from my process (myexe.exe arg0)
  2. Retrieve the PID of this new process (os windows)
  3. when I
3条回答
  •  忘掉有多难
    2020-12-15 08:50

    So if I understand you right the code should go like this:

    from subprocess import Popen, PIPE
    script = "C:\myexe.exe"
    param = "-help"
    DETACHED_PROCESS = 0x00000008
    CREATE_NEW_PROCESS_GROUP = 0x00000200
    pid = Popen([script, param], shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
    

    At least I tried this one and worked for me.

提交回复
热议问题