Saturday 9 June 2018

linux - Redirect stdout to a file when process is run in background


How can I redirect the stdout of a program to a file when it's run in the background?


I have a program that generates output every second. When I run it normally and redirect to a file, the output is in that file as expected:


#./program > file.txt
#cat file.txt
output
output
output
#

When I try to do the same thing in the background, the file will remain empty:


#./program > file.txt &
#cat file.txt
#

Answer



What about sh -c './program > file.txt; cat file.txt' & ?


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...