phpwindowssymfonysymfony-process

windows - Symfony2 Process crashes when passing env variables


Apologies in advance if this question has already been answered before. It's kind of hard to find something exactly like this. As the title already says, I'm trying to spawn a Symfony2 Process which executes a cmd file on Windows, a shell script on linux.

On linux everything works just fine. On Windows however, it crashes when I try to pass environment variables to my process.

http://symfony.com/doc/current/components/process.html

The code looks roughly like this:

$process = new Process('Z:\bin\webpack.cmd', 'Z:\var\www\webpacktest\www\app\cache\dev');
$process->setEnv([
    'PATH'      => getenv('path')
    'NODE_PATH' => 'Z:\\bin\\node_modules'
]);

$process->run();

The process exits with exit code (-1073741819) and produces no output whatsoever.

When I remove the setEnv method and not pass any env vars, the process runs perfectly.

edit: I'm running Windows 10 Home. Running PHP 5.6


Solution

  • I had exactly the same problem, as a work around I used putenv:

    putenv("NODE_PATH=Z:\\bin\\node_modules");
    $process = new Process('Z:\bin\webpack.cmd', 'Z:\var\www\webpacktest\www\app\cache\dev');
    $process->run();
    putenv("NODE_PATH=");
    

    In your example you don't need to pass PATH as you don't change it and it's inherited anyway.