PHP: Why isn't exec() returning output?
You should redirect stderr to stdout.
To do that, change your exec() call like this:
exec("ping -c 1 $domain_bad 2>&1", $output, $return_var);
More info about 2>&1
meaning here.
PHP system(), exec(), and shell_exec() not returning output
I think that the issue is not that you not get the output of the executed command, but which
fails to find mysql
.
Using exec
you can get the return status of your command, where 0
means successful, and other values indicate an error.
$output = exec($cmd, $output, $retval);
var_dump($output);
var_dump($retval);
If the $retval
is 1
that would mean which
doesn't find the mysql
binary, and returns an empty line.
php exec: does not return output
There are a few posts to the relevant sections of the PHP Manual such as this one:
I was having trouble using the PHP exec command to execute any batch
file. Executing other commands (i.e., "dir") works fine). But if I
executed a batch file, I receieved no output from the exec command.The server setup I have consists of Windows Server 2003 server running
IIS6 and PHP 5.2.3. On this server, I have:
- Granted execute permissions to the Internet User on c:\windows\system32\cmd.exe.
- Granted Everyone->Full Control to the directory in which the batch file is written.
- Granted Everyone->Full Control on the entire c:\cygwin\bin directory and its contents.
- Granted the Internet User "log on as batch" permissions.
- Specified the full path to each file being executed.
- Tested these scripts running from the command line on the server and they work just fine.
- Ensured that %systemroot%\system32 is in the system path.
It turns out that even with all of the above in place on the server, I
had to specify the full path to cmd.exe in the exec call.When I used the call:
$output = exec("c:\\windows\\system32\\cmd.exe
/c $batchFileToRun");
then everything worked fine. In my situation,
$batchFileToRun
was the
actual system path to the batch file (i.e., the result of a call to
realpath()).
There are a few more on both the exec
and shell_exec
manual pages. Perhaps following through them will get it up and working for you.
Related Topics
How to Parse a CSV File to Grab the Column Names First Then the Rows That Relate to It
Google Calendar API V3 - Authenticate with Hardcoded Credentials
Curl Error 60: Ssl Certificate in Laravel 5.4
Programmatically Creating New Order in Woocommerce
PHP Regular Expression - Filter Number Only
How to Display Currency in Indian Numbering Format in PHP
How to Customize Fos Userbundle Urls
How to Populate HTML Dropdown List with Values from Database
Codeigniter: Try Catch Is Not Working in Model Class
How to Set a Class Attribute to a Symfony2 Form Input
How to Enable PHP to Work with Postgresql
"No Such File or Directory" or "No Such Host Is Known" When Running Migrations
How to Render Zf2 View Within JSON Response
How to Paginate a Merged Collection in Laravel 5
Using Mx Records to Validate Email Addresses
Fatal Error: Call to Undefined Function SQLsrv_Connect() in C:\Xampp\Htdocs