There is a program (neural network), it outputs a large amount of information important for debag by printf() .

In the console console, of course, nothing fits. I would like to somehow redirect the entire output (from the beginning of the program to the end) to a file, so that after the program has finished its work, it should be easy to read. Google, found sentences like program.exe > output.txt , it doesn't work for me (as I understand it, this is because the program is interactive and requires some data to be entered by the user).

I work in Visual Studio 2015.

    4 answers 4

    Everything works for you (should work), just all invitations to the user, also output by printf , go to the file. Most likely, you accept the absence of input prompts for “not working”.

    Either rewrite, or when debugging, simply enter values ​​without invitations - you know what and when you need to enter :) You can even shove all the necessary input into the file and call

     prog.exe < input.txt > output.txt 
    • Really. As you wrote, I was mistaken, in fact, everything works, just invitations to the user are not displayed in the console. Thank you - kekyc

    Just re- open ( freopen ) at the right time (after the end of the dialogue) stdout to another file.

    You can pass the name of this file in the main argument.

    Those. something like this:

     #include <stdio.h> int main (int ac, char *av[]) { puts("Go..."); // здесь весь диалог if (av[1]) if (!freopen(av[1], "w", stdout)) return perror(av[1]), 1; int i; for (i = 0; i < 5; i++) printf("%d\n", i); // если требуется продолжить вывод в консоль if (av[1]) freopen("con", "w", stdout); puts("End"); return 0; } 

      You can use the wtee program — an analogue of the tee command from * nix (copies output from the program to both the terminal and the file): yourprogram | wtee output.txt yourprogram | wtee output.txt . Input prompts will be visible in the terminal, plus the program output will be saved to a file.

      • A. A useful thing. Thanks, now I will use :) - kekyc

      And why the program itself does not create a file for example with a date in the title and does not add to it the result of its work? For example, using fputs() where printf()

      • Yes, of course, I thought about this option. But rewriting will have a lot. If you do not offer any faster options, you will have to do so .. - kekyc