Help: Pass an Input to a Program for test

Apr 13, 2011 at 2:59am

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 Apr 13, 2011 at 3:11am
Apr 13, 2011 at 3:18am
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.
Apr 13, 2011 at 3:55am
@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
Apr 13, 2011 at 4:04am
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.


Apr 13, 2011 at 4:43am
@sohguanh: could you please write exactly what I must write in the command part after" step2" to see the output?
Last edited on Apr 13, 2011 at 4:43am
Apr 13, 2011 at 7:30am
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
Apr 13, 2011 at 5:25pm
@ne555: Thanks for help...i just trying to learn Linux by myself anyway thanks for clear explain.
Apr 23, 2011 at 8:55am
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.