I code in C and run programs in a Linux terminal. I want to save the output of a program in a .txt file. I usually do this by doing./a.out>filename.txt
./a.out>filename.txt
But I wrote an interactive program in which I need to enter a number to start the program. In this case, how to do it?
Thank you very much and your valuable suggestions are most welcome.
Move the requirement to enter the number from the terminal into the command line parameter.
./a.out 42> filename.txt
Or, more simply, accept input from redirected input
echo 42 | ./a.out> filename.txt ./a.out <input.txt> filename.txt
script .
script
$man script
./a.out | tee filename.txt
Tee
Assuming you enter the number you want to pass to the program into a file called 'input.txt'. If you want to redirect the output to 'output.txt', at a command prompt, type:
./a.out < input.txt > output.txt
Source: https://habr.com/ru/post/1795881/More articles:Changing the height of CytoPanel - javaProblems including jsonCpp headers - c ++Wrapping HTML text in JEditorPane inside JScrollPane - javaFind the nearest point of each point (nearest neighbor) - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1795880/fix-regular-expression-for-emails-to-not-allow-consecutive-periods&usg=ALkJrhimTSh3AbZeGc4Wr3VxVnaFTl__GgFourier-based character recognition in Matlab - matlabAndroid: PopupWindow Animation - you need to know when the animation is over - androidAOS 4.x error with animation - androidSession bullying in MVC 3 - unit-testingAJAX request for ASP.NET web service - what type of parameter to use? - jsonAll Articles