Say I have a C program and in it I want to execute a shell command and redirect its output to file, by using the stdlib system function.
system("bash -c \"echo $HOME\" > a.txt");
Now this is for illustration, it actually doesn't work. How do I make the output redirection work? Because I'm calling bash from a function I need the process itself to do the redirecting.