0

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 by SakuraPink: n/a

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by SakuraPink
0

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 by nezachem: n/a

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.