Help: Pass an Input to a Program for test


Hey guys I started to run a C++ my program in Linux and I don't know how to test my program that works fine with a text file. This is a project for my uni and to explain more clear, My program is a sample database for modify or add and search and it read data from a binary file and also write into a binary file.
I have got an input from my lecture and she said after compiling in Linux I must
write:

1-to compile: g++ (files with cpp)

2-to see the output: ./a.out

3-to test with input: ./a.out < input.txt >


My problem is in step three.Please help
Last edited on
I usually do Step 3 in a different way but should be same objective.

cat input.txt | ./a.out > output.txt

I like it this way as it convey the workflow from open up an input file, feed to a program to process and then write to a output file. I find this easier to visualize.
@sohguanh: cat just display what is inside the file I want to send this file as a input to my program and see if there is any error inside my code
Notice I also use a | command ? Basically cat display what is inside the file and those contents are "pipe-ed" as input into your a.out program.

Unix has these wonderful operators. It is good to learn how to use them.


@sohguanh: could you please write exactly what I must write in the command part after" step2" to see the output?
Last edited on
Does your program read from standard input (cin, scanf) an write to standard output (cout, printf) ? Also you said that it works with binary files, not text files, so what are you expecting to see?

$ ./program.bin Executes the program, read from keyboard write to the console
$ ./program.bin < input_file Executes the program, read from input_file write to the console.
$ ./program.bin > output_file The output is send to the output_file
$ ./program.bin | tee output_file Write to the output_file and also visualise in the console

If you want to redirect the error stream (cerr) use $ ./program.bin 2>error_log
To send both error and normal output to the same $ ./program.bin 1>out_file 2>&1
@ne555: Thanks for help...i just trying to learn Linux by myself anyway thanks for clear explain.
Basically, show what is inside the cat file, which is about "control code" for the a.out input to your program.Last time I saw a [url="http://www.buyctjewelry.com/C-61-b0"]Cartier Pendants[/url] and actually that not charming enough but I really like it.And what a pity I lost it finally so I really regret now!
Topic archived. No new replies allowed.