Posted on October 12, 2018 at 12:59 pm
With PHP you can use shell_exec() to execute a command via shell and return the complete output as a string, here si a quick example to do so:
$output = shell_exec('ls -lart');
However some commands like “gunzip -t” may show empty results.
To fix that, just add 2>&1 to the end of the command, i.e:
echo shell_exec("gunzip -c -t /path/to/file.gz 2>&1");
The issue was a line break at the beginning of the gunzip output.
Thanks to Trev for this smart tip!
- PHP Display Date Same as Server HTTP Headers Date
- Google Cloud Load Balancer Firewall Rules
- Create Instance Template out of Disk Snapshot on Google Cloud
- Get User IP Address From Google Cloud Load Balancer
- Connect as Root using WinSCP on Google Cloud Compute Engine
- Become Root on Google Cloud Compute Engine VMs
- Connect to Google Cloud Compute Engine VM via PuTTY SSH
- DigitalOcean Slow, My Experience
- PHP GetHostByAddr() Slow? Make it Faster
- PHP GetHostByName() Slow? Make it Faster
- How to Match Newline with Strpos() in PHP
- Use PHP Strpos() to Check if a String Starts with
- How to Run a Command with Time Limit in Bash Linux
- Unable to extract and upload PackageInfo.xml
- Stop Bad Bots from Crawling Your Website
- DEB.SURY.ORG Updated the Signing Key (March 2019)