Reputation: 238
shell_exec() is not working on my localhost. I read a lot of websites to resolve this issue but can't find a solution. This code:
$output = shell_exec("env");
print "<pre>$output</pre>";
Doesn't give any output.
I checked in php.ini disable_functions
but shell_exec
is not disabled.
I did error_reporting = E_ALL
but again no output (no error). All I get is just a blank screen. Even safe_mode
is off.
If I write echo "BULB";
after the above code it is printing "BULB".
What could be the issue?
Upvotes: 1
Views: 2924
Reputation: 5032
What info are you expecting to get from env
? From your comments, it seems to me as if you're trying to use a Linux command on a Windows system -- that's never going to work.
On Linux systems, the env
command on its own like that returns a list of environment variables that have been defined. However env
is not a valid command in Windows.
If you're simply looking for the list of environment variables, this can actually be obtained in PHP without having to go to a shell command. PHP has a built-in global variable $_ENV
which contains a copy of all the environment variables that were defined when the program stated. Simply print_r($_ENV)
to see them.
On the other hand, if you really need to use shell_exec()
for some reason, then you need to take into account the operating system that you're using. On Linux you would use env
command. The equivalent on Windows is set
without any arguments. So your code becomes:
$output = shell_exec("set");
Note that the format of the output may not be identical to what you'd get on Linux, so if you're parsing it, that code will have to change too.
If you need your code to be able to run on multiple platforms then you would need to write additional code before the shell_exec()
call to determine the operating system and work out the correct command to use.
Upvotes: 2