norkunas / youtube-dl-php

A PHP wrapper for youtube-dl or yt-dlp.
MIT License
456 stars 158 forks source link

Can't set environment variable for process on Windows OS #198

Closed cadlec closed 1 year ago

cadlec commented 1 year ago

Hi!...I've got the error #39 too. And after setting the bin path and python path, it didn't work.

But, I've been able to fix the error by adding this code in DefaultProcessBuilder.php file:

$process = new Process($arguments, null, [ 'SYSTEMROOT' => 'C:\WINDOWS', ])

So, I think we need a way to set the Windows environment variable in order to fix definitely this error.
My proposition is to create a setter for this environment variable. Thanks

norkunas commented 1 year ago

Hello,

Reading Symfony Process Docs there is a note:

In addition to the env vars passed explicitly, processes inherit all the env vars defined in your system.

So this shouldn't be needed. You should look for a reason why it doesn't inherit it.

norkunas commented 1 year ago

But anyway, as a workaround instead of patching DefaultProcessBuilder you could just implement a custom YoutubeDl\Process\ProcessBuilderInterface where you set your env vars and then provide it to YoutubeDl as a first argument when constructing, to ensure that it will work always for you even after composer update.

cadlec commented 1 year ago

Thank you @norkunas , your workaround is what I've done and it worked !