PHP on a windows machine; Start process in background

后端 未结 5 1343
无人及你
无人及你 2020-12-10 06:46

I\'m looking for the best, or any way really to start a process from php in the background so I can kill it later in the script.

Right now, I\'m using: shell_exec($C

5条回答
  •  隐瞒了意图╮
    2020-12-10 07:22

    On my Windows 10 and Windows Server 2012 machines, the only solution that worked reliably within pclose/popen was to invoke powershell's Start-Process command, as in:

    pclose(popen('powershell.exe "Start-Process foo.bat -WindowStyle Hidden"','r'));
    

    Or more verbosely if you want to supply arguments and redirect outputs:

    pclose(popen('powershell.exe "Start-Process foo.bat 
                 -ArgumentList \'bar\',\'bat\' 
                 -WindowStyle Hidden
                 -RedirectStandardOutput \'.\\console.out\' 
                 -RedirectStandardError \'.\\console.err\'"','r'));
    

提交回复
热议问题