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.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.