Then it's definitely not a bash(1) issue but a C++ one.
I think your wrong.
The OP actually asked :
The program saves files in its own directory. How can I tell it to save all output files in an existing subdirectory "data"? Or even better, check the existence of a subdirectory "data", create "data" if it does not exist, and tell the program to save there.
It seems like your telling him it can't be done... it can.
# If a sub directory named "data" doesn't exist, if it doesn't create it
if [ ! -d "data" ]; then
# Tell the program to save there ...
# The simplest method would be to move (mv) them after
they are created
# Say they all had the extention .final ...then
(echo $p; echo 10; echo 10; echo 2000; echo 1000) | ./finalsim
mv *.final data/
# How about you just cd to data and THEN run the program
# Notice the TWO dots in front of your command, as it's in the dir above
(echo $p; echo 10; echo 10; echo 2000; echo 1000) | ../finalsim
Maybe not extremely pretty, perhaps not perfect.....but it works.
The only thing that you may have to take into account with the second method, is if your "finalism" program is getting data from the original directory
Hope that helps.