stdout redirect in exec function
Posted: Fri Mar 20, 2009 7:34 am
Hi.
I have a little problem redirecting the output of program called from exec function in php.
Simple example:
ls -al will of course be replaced with something else later.
I know that the output this produces will be in $output BUT, i don't know why it's not in the my_file.txt file.
I need the output to be writen to a file while it's produced. I don't need it after to process has finished.
I will have some other program reading my_file.txt while it's being writen to by some other process.
If you try ls -al &> my_file.txt in your console, it will work. But not if you do it this way in php.
Do you have any idea why this doesn't work in php ?
Thank you!
I have a little problem redirecting the output of program called from exec function in php.
Simple example:
Code: Select all
$output = shell_exec('ls -al &>my_file.txt');
I know that the output this produces will be in $output BUT, i don't know why it's not in the my_file.txt file.
I need the output to be writen to a file while it's produced. I don't need it after to process has finished.
I will have some other program reading my_file.txt while it's being writen to by some other process.
If you try ls -al &> my_file.txt in your console, it will work. But not if you do it this way in php.
Do you have any idea why this doesn't work in php ?
Thank you!