AdeleGoldberg
AdeleGoldberg

Reputation: 1339

How to redirect logs from a background process

I have C++ program called MyApp like below

#include <iostream>

int main(int argc, char *argv[]) {

    for(int a = 0; a < 50; a++) {
        std::cout << "Hello stackoverflow" << std::endl;
    }
    return 0;
}

I built it for Linux to run as a console application. I run it from the terminal just by calling it with the following command.

MyApp & >> /some/output.txt

Question:
As you can see above, I want the log output to go into /some/output.txt. That works great. But the problem is that the logs parallel to adding the couts into the txt file, it keeps spamming the console as well! How can I make the couts go into /some/output.txt and not spam the console? Is there a way to do that or should I have to change the C++ logic in MyApp to do that?

Upvotes: 2

Views: 1449

Answers (1)

Armali
Armali

Reputation: 19375

MyApp > /tmp/output.txt & – Brian Agnew

Upvotes: 4

Related Questions