Reputation: 441
I have a simple C program where the it will ask to take an integer from the user, and then it will print that integer.
#include <stdio.h>
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);
printf("You entered: %d", number);
return 0;}
When I use this command:
gcc program.c -o test
./test | tee text.txt
The program running on terminal does not print the enter integer line but instead, waits for an input and when I provide that input, it prints it and also into the text.txt folder. I want to run the program as it is and store everything running on terminal into the text.txt folder including both the input and the output. Any possible way to do that?
Upvotes: 2
Views: 990
Reputation: 8406
For Debian based Linuxes, run apt install devscripts
, and then try the annotate-output
util. For example, run cat
using a process substitution and a file that's not there at all:
annotate-output cat <(echo hello) /bin/nosuchfile
...which shows what otherwise would be input, output, and standard error output, all sent to standard output which could then be piped to a file:
13:01:03 I: Started cat /dev/fd/63 /bin/nosuchfile
13:01:03 O: hello
13:01:03 E: cat: /bin/nosuchfile: No such file or directory
13:01:03 I: Finished with exitcode 1
Upvotes: 0
Reputation: 181094
The tee
command works with one input, but you want to capture two. With some care, you could use two separate tee
commands two copy both the input and the output to the same file, but you would be better off with a utility designed for your purpose, such as script.
Upvotes: 2