2

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

4

1 回答 1

2

我遇到了完全相同的问题,作为我使用 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=");

在您的示例中,您无需通过PATH,因为您无需更改它,并且无论如何它都是继承的。

于 2016-04-18T14:23:10.507 回答