-1

I want to check if the user has install angular cli with running ng --version on PHP with exec, proc_open or shell_exec but return is empty. I dont have problems if I execute in cmd or in terminal's Visual Studio Code in any path on Windows.

I'm use wampserver

1 Answers1

0

There are multiple ways to do it, and you have to consider what you will do if there are more than one found. You can find it:

exec('where /r C:\ ng.exe', $paths);

And then if you really need the version, use the first one if it starts with C:\:

if(strpos($paths[0], 'C:\\') === 0) {
    exec($paths[0] . ' --version', $version);
}
print_r($version);

If it isn't found then $paths[0] should contain:

INFO: Could not find files for the given pattern(s).

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87