How can I redirect stdout to some visible display in a Windows Application?

后端 未结 8 1345
时光取名叫无心
时光取名叫无心 2020-11-27 03:31

I have access to a third party library that does \"good stuff.\" It issues status and progress messages to stdout. In a Console application I can see these messages just f

8条回答
  •  醉话见心
    2020-11-27 04:10

    You can redirect stdout, stderr and stdin using freopen.

    From the above link:

    /* freopen example: redirecting stdout */
    #include 
    
    int main ()
    {
      freopen ("myfile.txt","w",stdout);
      printf ("This sentence is redirected to a file.");
      fclose (stdout);
      return 0;
    }
    

    You can also run your program via command prompt like so:

    a.exe > stdout.txt 2> stderr.txt
    

提交回复
热议问题