0

I have a C program which gives some output. I am compiling the C program via the shell but I need the output from the run C program and store in shell.

Edit.

Save the output to a shell Variable.

umesh moghariya
  • 185
  • 3
  • 10

2 Answers2

4

I assume that you want to store the output of the program in a variable. Unix shells offer a facility that's called command substitution to do just that. Depending on your shell, you can do either :

output=$(./run)

or

output=`./run`

Bash supports both. If, however, you want to save the output to a file, you will need to redirect the standard output stream to a file. You can do this like this :

./run > output.txt

Or, if you want to see the output while the program is running and save it to an output file as well, you can use the tee utility and pipe the output of your program to it.

./run | tee output.txt
Daniel Kamil Kozar
  • 18,476
  • 5
  • 50
  • 64
1

You can redirect your output into a file like this:

./run > file

If you want to store it into a variable, you have to decide which shell we're talking about. It depends whether you have a windows shell, or linux bash..

duedl0r
  • 9,289
  • 3
  • 30
  • 45