Closed divinity76 closed 5 months ago
I use Ubuntu and it works fine here 🤔
λ command -v google-chrome
/usr/bin/google-chrome
I use Ubuntu and it works fine here 🤔
λ command -v google-chrome /usr/bin/google-chrome
yeah in your shell with your shell builtins, but try
php -r 'var_dump(shell_exec("command -v google-chrome"));'
and then try
php -r 'var_dump(shell_exec("bash -c '\''command -v google-chrome'\''"));'
Same thing in both:
λ php -r 'var_dump(shell_exec("command -v google-chrome"));'
string(23) "/usr/bin/google-chrome
"
λ php -r 'var_dump(shell_exec("bash -c '\''command -v google-chrome'\''"));'
string(23) "/usr/bin/google-chrome
"
@enricodias well that confuses me, what do you get by
type command;
php -r 'var_dump(shell_exec("which command"));'
?
When I do it, I get
hans@DESKTOP-EE15SLU:/$ type command; php -r 'var_dump(shell_exec("which command"));'
command is a shell builtin
NULL
I got the same;
command is a shell builtin
NULL
It is a builtin, but shell_exec
can still use it.
@enricodias wow.. you're entirely correct!
I could've sworn that
php -r 'var_dump(shell_exec("command -v google-chrome"));'
didn't work for me yesterday, and concluded that shell_exec() doesn't have access to shell builtins,
... but it does work now! nevermind 🤷♂️ and sorry
on Ubutu Linux, "command" is a bash builtin, not a standalone binary, and shell_exec() tries to find the "command" binary and fails, thus the original code never worked on Ubuntu Linux (I think the same is true for the entire Debian-derived family of operating systems, but don't quote me on that), fixing that by doing
bash -c 'command...
instead.Also added chromium support, for those who have Chromium but not Chrome installed.
It will look for Chrome first, and if it cannot find Chrome, it will look for Chromium second, and if all fails, it falls back to hardcoded "chrome".