php shell_exec() out put to get a text file

Roshan Wijesena picture Roshan Wijesena · Apr 19, 2011 · Viewed 12.2k times · Source

I'm trying to run rate -c 192.168.122.0/24 command on my Centos computer and write down the output of that command to the text file using shell_exec('rate -c 192.168.122.0/24') command; still no luck!!

Answer

Matthieu Napoli picture Matthieu Napoli · Apr 19, 2011

If you don't need PHP, you can just run that in the shell :

rate -c 192.168.122.0/24 > file.txt

If you have to run it from PHP :

shell_exec('rate -c 192.168.122.0/24 > file.txt');

The ">" character redirect the output of the command to a file.