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!
- Block Paltalk Ads (and Others) via Hosts file
- E: Sub-process /usr/bin/dpkg returned an error code (2)
- How to Validate JSON in PHP
- The program can’t start because VCRUNTIME140.DLL is missing
- PHP CURL Download Remote URL to File
- PHP Check if a file was modified more than 1 hour ago
- Linux -bash: Input/output error or -bash: Read-only file system
- Dropzone.js: Drag’n’Drop File Uploads with Image Previews
- Lost connection during Debian apt-get upgrade
- Bootstrap 3 Navbar with Logo Image
- Redis HMGET, HGETALL, HSET, HGET Benchmark
- PHP GetHostByName() Slow? Make it Faster
- Use Timestamp with new DateTime() in PHP
- Calculate Elapsed Time Between Two Dates in PHP
- PHP Display Date Same as Server HTTP Headers Date
- PHP cURL Download Size Limit