> and >> operators have no effect
when trying to write the output of a php script to a file I get the weirdest error. I use:
#php daily.php > error/daily
Well, all this does is output it in the console anyway. The file (error/daily) is untouched.
error/daily has chmod 777. Different constructs like
#php daily.php >> error/daily
don't work either. The output of daily.php just keeps being output in the console...
Got any ideas on this? :/ Thanks in advance!
UPDATE:
Now using
#php daily.php 2> error/daily
it outputs nothing in the console.
But error/daily is untouched, nothing is written to it.
Another UPDATE:
#php daily.php 2>> error/daily
开发者_StackOverflow中文版works as expected (appends error output to file), while
#php daily.php 2> error/daily
simply empties the file and writes nothing into it. Any idea why this could be happening?
So this is at the shell prompt? Those parentheses cause the enclosed command to be executed in a new invocation of the shell; the redirects will apply to the output of the shell itself, of which there is none. Commands that the shell executes will still print their output to the console. Just drop the parentheses; they're unnecessary and the source of your problem.
In a terminal, programs have two outputs : standard output and error output. By default both display in the console.
The > (and >>) operator redirects the standard output to a file but leaves the error output in the console.
Since it seems you are trying to redirect errors to a file, php must be writing to the error output. To accomplish what you want to do you must do
php daily.php 2> error/daily
If you want to redirect both outputs you can also do
php daily.php 2> error/daily 1>&2
Edit: Don't do that. If you want to redirect both outputs, redirect in different files. For instance:
php daily.php 2> error/daily 1> output.txt
精彩评论