writing output of a program to a file only when all of it is ready
I run a mysql batch job and want it's results redirected into a text file.
mysql -t -h localhost -u user -p=password <queryfile> output I pull up this file(output) in my browser to view results. the only problem with this seems to be that as soon as mysql query starts executing it opens up the output file and deletes its contents so there are few seconds when this file is empty. Is there any way to redirect output to a file so that it doesn't write or open a file untill all of it's data is ready. Then it should open file for writing and delete it's results. Hope this made sense and thanks for all your replies. |
As far as I'm aware the answer is No.
What you could do though is write the output of the mysql command to a different file, then cat the contents of that to the file output. E.g. Code:
foo=`mktemp` |
amazing. exactly what i needed. thanks a bunch
|
It just occured to me that if you were to do
Code:
(mysql -t -h localhost -u user -p=password <queryfile) < output |
Quote:
( edit: just tried it by doing a yes | cat - >/tmp/yes.out & cat /tmp/yes.out and the redirection does not lock the output file) ) 'mv' might be a better choice than cat as it's a more atomic operation and as long as it's moving within the same filesystem wouldn't require the extra copying of data. Code:
foo=`mktemp` disclaimer: I've not played with mysql, so I don't know whether it returns 0 on success or not, but it gives you something more to think on. |
All times are GMT -5. The time now is 12:01 AM. |