1

I have a C++ program in Linux (Ubuntu) which prints very long output in a command terminal.

How can i copy this output from command terminal directly to the .txt file by Linux command?

2 Answers 2

5

Your shell does this for you by virtue of output redirection:

$ ./a.out > theoutput.txt
Sign up to request clarification or add additional context in comments.

2 Comments

There is an error when i execute this command: bash: ./a.out: No such file or directory
@BlueBit: substitute the actual filename of own program... (or just call all your programs a.out, as you were meant to :-))
2

In general you type;

command > file.txt

The greater than symbol > redirects standard out to the file.

3 Comments

Exactly. You "pipe" the output to a file.
Well actually pipe would be used to send stdout to stdin of another process i.e. "command | command2". Not the same thing.
An improvement would be to keep stdout and stderr separately: command 1>outFile 2>errFile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.