I have a command that compiles test.cpp and is supposed to store output in the output file. Here is an example of my generated cmd:
g++ tmp/test.cpp -o tmp/test &> tmp/compile.out
when I use system(), it does not work. Even though it creates output file, it still prints everything to the main console window. When I execute it in terminal, it works just fine.
I also tried use popen() and fgets() (just copying the code from here) but same happened. I probably could just fork my process and use freopen or something but I have sockets and multiple threads running in the background. I guess they would be duplicated as well, which is not good.
Any ideas why it may fail?
According to the man-page of
system, it invokesshwhich is the standard bourne shell (not bash, Bourne Again SHell). And the bourne shell doesn’t understand&>. So you might need to use the old style: