Hi all,

I want to run a cpp code a couple of times using a shell. Cpp code needs a text file as an input. I have been trying to pass the file to the cpp code no success.
The following is what I have done so far:

#! /bin/bash

g++ 3Distance.cpp
./a.out 
echo file1.xml 
> 3d-1.xml

For later I like to use file$i.xml instead of file1.xml in the above.

any suggestion is very much appreciated.

Edited 5 Years Ago by SakuraPink: n/a

Depends on how the executable (which you refer to as cpp) expects the input:
1. It reads the filename:

echo file1.xml | ./a.out > 3d-1.xml

2. It reads the contents of a file:

./a.out < file1.xml > 3d-1.xml

3. It takes a filename as an argument:

./a.out file1.xml > 3d-1.xml

All of the above presumes that a.out writes its output to stdout.

Edited 5 Years Ago by nezachem: n/a

Thanks. I used the first one and the code run as I expected but using the 2nd one it seems that the cpp code run but it did not use the file.xml data. I am guessing that is what you mean by saying it depends how my cpp code takes the input.

This question has already been answered. Start a new discussion instead.