Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dump php system command output to a file

In the php system command we use the following

system("ffmpeg -i test.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv output_file.flv 2>&1 &"). 

Please explain the usage of the above mentioned system command. What does '2>&1 &' stand for ? I want to dump the process details to a file how do I do that ?

Thank you very much.

like image 243
Pawan Rao Avatar asked Apr 17 '26 07:04

Pawan Rao


1 Answers

2>&1 redirects «stderr» to «stdout», & at the end makes the command run in background.

To make it complete it should be

«command» 2>&1 > /tmp/somefile.log &

Without redirecting «stdout» to a file (or to /dev/null) running in background from system() doesn't make much sense, as your command would get killed as soon as PHP terminates (e.g. reaching time limit).

From system() manual:

Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

like image 145
vartec Avatar answered Apr 18 '26 20:04

vartec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!